Undefined references when trying to link Qt app with my static library

前端 未结 3 347
小鲜肉
小鲜肉 2021-01-12 19:33

I have a static library that I have built with MinGW, I am trying to link to that library from a Qt application. I keep getting linker errors caused by one of the object fi

相关标签:
3条回答
  • 2021-01-12 20:11

    you may have used gcc instead of g++. gcc is a C compiler. but g++ is a c++ compiler.

    just make sure to use g++ if you have .cpp files.

    0 讨论(0)
  • 2021-01-12 20:12

    Just in case anyone else has this problem: my project rebuild was using .o files from a previous build. I changed compilers in between.

    Turns out that when I rebuilt the same project, the new compiler didn't build new .o files, so they were missing some key info. After deleting the old files and rebuilding, the error was fixed.

    I assume rebuilding from scratch, without the delete, would work the same.

    0 讨论(0)
  • 2021-01-12 20:30

    It seems that your static library was linked against one MinGW distribution (i.e. 3rd version) but you try to link your application with this library using other MinGW distribution (i.e. 4th version which is distributed with binary Qt). You should rebuild your library using the same MinGW which you use for your application development.

    Update

    May be it's another well known problem. Take a look at this topic. You probably have 2 different folders with Qt libs

    C:\Qt\2009.05\bin;C:\Qt\2009.05\qt\bin 
    

    in your path too. Libraries in the first folder (...\bin) compiled with VS2008 and libraries in the second one (...\qt\bin) compiled with MinGW. The items in path variable are looked up when your application starts. Suddenly the folder with "wrong" libraries exists before the folder with correct item in your path variable. What you can do is to copy QtCore4.dll, QtGui4.dll and other libraries that you need to folder with your application executable. Hope this helps.

    Some links about this problem:

    • @qtforum.org
    • @some blog post (in Russian =))
    0 讨论(0)
提交回复
热议问题