building and linking a shared library

前端 未结 1 1780
借酒劲吻你
借酒劲吻你 2020-12-02 21:17

im trying to build a shared library on a windows cygwin platform using g++, and later link it with another cpp file: i use the following commands:

// generat         


        
相关标签:
1条回答
  • 2020-12-02 21:51

    When using -l<libname> to specify library to link, the linker will first search for lib<libname>.so before searching for lib<libname>.a.

    In your case it doesn't work, because the library filename is not with .so suffix.

    You may create simlink

    libbeat.so -> libbeat.so.1.0.1
    

    or

    libbeat.so -> libbeat.so.1
    libbeat.so.1 -> libbeat.so.1.0.1
    

    You can also use -l:libbeat.so.1.0.1 (if your linker supports it, check in man ld description of -l parameter). Another option is to specify the library without -l

    g++ -o checkbeat checkbeat.cpp -I . -L. libbeat.so.1.0.1
    

    Note that the library you link to should be put after object/source file using its symbols - otherwise the linker may not find the symbols.

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