c++ undefined references with static library

后端 未结 5 1442
青春惊慌失措
青春惊慌失措 2020-12-02 09:55

I\'m trying to make a static library from a class but when trying to use it, I always get errors with undefined references on anything. The way I proceeded was creating the

5条回答
  •  盖世英雄少女心
    2020-12-02 10:18

    This is probably a link order problem. When the GNU linker sees a library, it discards all symbols that it doesn't need. In this case, your library appears before your .cpp file, so the library is being discarded before the .cpp file is compiled. Do this:

    g++ -o main.exe main.cpp -L. -lmylib
    

    or

    g++ -o main.exe main.cpp myClass.lib
    

    The Microsoft linker doesn't consider the ordering of the libraries on the command line.

提交回复
热议问题