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

前端 未结 3 1154
太阳男子
太阳男子 2020-11-29 23:35

I have a shared library that I wish to link an executable against using GCC. The shared library has a nonstandard name not of the form libNAME.so, so I can not use the usual

相关标签:
3条回答
  • 2020-11-30 00:11

    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
    
    0 讨论(0)
  • 2020-11-30 00:15

    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.

    0 讨论(0)
  • 2020-11-30 00:19

    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

    0 讨论(0)
提交回复
热议问题