C++ shared library undefined reference to `FooClass::SayHello()'

前端 未结 1 419
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 18:10

I\'m making a C++ Shared Library and when I compile a main exe that uses the library the compiler gives me:

main.cpp:(.text+0x21): undefined reference to `Fo         


        
相关标签:
1条回答
  • 2020-12-15 18:26
    g++ -I. -L. -lfoo main.cpp -o main
    

    is the problem. Recent versions of GCC require that you put the object files and libraries in the order that they depend on each other - as a consequential rule of thumb, you have to put the library flags as the last switch for the linker; i. e., write

    g++ -I. -L. main.cpp -o main -lfoo
    

    instead.

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