How to link using GCC without -l nor hardcoding path for a library that does not follow the libNAME.so naming convention?

冷暖自知 提交于 2019-11-27 03:30:27

There is the ":" prefix that allows you to give different names to your libraries. If you use

g++ -o build/bin/myapp -l:_mylib.so other_source_files

should search your path for the _mylib.so.

If you can copy the shared library to the working directory when g++ is invoked then this should work:

g++ -o build/bin/myapp _mylib.so other_source_files

If you are on Unix or Linux I think you can create a symbolic link to the library in the directory you want the library.

For example:
ln -s build/bin/_mylib.so build/bin/lib_mylib.so

You could then use -l_mylib

http://en.wikipedia.org/wiki/Symbolic_link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!