Linking Boost libs required by ASIO on Windows giving undefined reference errors
-
I am trying to use a boost/asio. For simplicity, I have one main.cpp as below that includes boost/asio.hpp
@
#include <boost/asio.hpp>int main(int argc, char *argv[])
{
return 0;
}
@my .pro file looks like this
@
QT += core guiCONFIG += console
TARGET = SIDController
TEMPLATE = appINCLUDEPATH += $$PWD/../../../libs/boost_1_44
SOURCES += main.cpp
win32: LIBS += -L$$PWD/../../../libs/boost_1_44/stage/lib/ -llibboost_filesystem-vc100-mt -llibboost_system-vc100-mt
INCLUDEPATH += $$PWD/../../../libs/boost_1_44/stage/lib
DEPENDPATH += $$PWD/../../../libs/boost_1_44/stage/libwin32: PRE_TARGETDEPS += $$PWD/../../../libs/boost_1_44/stage/lib/libboost_filesystem-vc100-mt.lib
win32: PRE_TARGETDEPS += $$PWD/../../../libs/boost_1_44/stage/lib/libboost_system-vc100-mt.lib
@When I compile I get these errors
bq. Running build steps for project SIDController...
Configuration unchanged, skipping qmake step.
Starting: "C:\Qt\2010.05\mingw\bin\mingw32-make.exe"
c:\qt\2010.05\qt\bin\qmake.exe -spec ......\Qt\2010.05\qt\mkspecs\win32-g++ -o Makefile ..\SIDController\SIDController.pro
C:/Qt/2010.05/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directoryC:/workspaces/qt/SIDController-build-desktop' g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -mthreads -Wl -o debug\SIDController.exe debug/main.o debug/mainwindow.o debug/voiceview.o debug/serialsid.o debug/moc_mainwindow.o debug/moc_voiceview.o -L"c:\Qt\2010.05\qt\lib" -LC:/workspaces/qt/SIDController/../../../libs/boost_1_44/stage/lib/ -llibboost_filesystem-vc100-mt -llibboost_system-vc100-mt -lQtGuid4 -lQtCored4 mingw32-make[1]: Leaving directory
C:/workspaces/qt/SIDController-build-desktop'
debug/mainwindow.o: In function_static_initialization_and_destruction_0': C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:214: undefined reference to
boost::system::generic_category()'
C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:215: undefined reference toboost::system::generic_category()' C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:216: undefined reference to
boost::system::system_category()'
debug/mainwindow.o:C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:211: undefined reference toboost::system::system_category()' debug/mainwindow.o:C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/asio/detail/impl/winsock_init.ipp:39: undefined reference to
WSAStartup@8'
debug/mainwindow.o:C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/asio/detail/impl/winsock_init.ipp:48: undefined reference toWSACleanup@0' debug/serialsid.o: In function
_static_initialization_and_destruction_0':
C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:214: undefined reference toboost::system::generic_category()' C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:215: undefined reference to
boost::system::generic_category()'
C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\SIDController.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:\Qt\2010.05\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project SIDController (target: Desktop)
When executing build step 'Make'When I Google these error, it looks like these are errors you get when boost_system and boost_filesystem are not linked correctly, but I'm pretty sure I'm setting it up properly in the .pro file. I tried all sorts of variations on LIBS +=. I used every flavor of boost_system and boost_filesystem, including mt, s, with the -1_44 at the end, without it. I built boost using "build-type=complete" and used every variation that that produced.
Arg, I'm completely stuck and cannot continue my project until I can figure this out. It really doesn't make any sense why these files are not linking properly. Please can anyone help.
-
Ping? This is really a deal breaker for Qt. I really need a way to link those libraries correctly. I've poured through the qmake documentation and can't find anything new that might help me. I don't usually post to forums unless I get really desperate. So help! :)
-
While we all appreciate the urgency you feel for your problem, please don't badger everyone for help. Especially after less than an hour and a half. Doing so is very rude and, if anything, will hinder your chances of getting effective and timely help.
If anyone has useful input regarding your problem, they will post. Be patient.
-
Your compilation log does not fit with your example: in your log, your linker tries to link
@main.o mainwindow.o voiceview.o serialsid.o moc_mainwindow.o moc_voiceview.o@
In your .pro file, you have only one file, without preprocessing (moc)After a bit of googling, (stackoverflow), seems to be a common problem, even without using Qt... Did you manage to link something without Qt already with boost ? From what I've read, you're doing it right.
-
You are correct. Excuse the misleading compile output. I was trying to say that the important part of the output was the reference errors. Here is a more appropriate output generated from the exact example above.
bq.
Running build steps for project SIDController...
Configuration unchanged, skipping qmake step.
Starting: "C:\Qt\2010.05\mingw\bin\mingw32-make.exe"
C:/Qt/2010.05/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directoryC:/workspaces/qt/SIDController-build-desktop' g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -mthreads -Wl -o debug\SIDController.exe debug/main.o -L"c:\Qt\2010.05\qt\lib" -LC:/workspaces/qt/SIDController/../../../libs/boost_1_44/stage/lib/ -llibboost_filesystem-vc100-mt-sgd-1_44 -llibboost_system-vc100-mt-sgd-1_44 -lQtGuid4 -lQtCored4 mingw32-make[1]: Leaving directory
C:/workspaces/qt/SIDController-build-desktop'
debug/main.o: In function_static_initialization_and_destruction_0': C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:214: undefined reference to
boost::system::generic_category()'
C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:215: undefined reference toboost::system::generic_category()' C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:216: undefined reference to
boost::system::system_category()'
debug/main.o:C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:211: undefined reference toboost::system::system_category()' debug/main.o:C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/asio/detail/impl/winsock_init.ipp:39: undefined reference to
WSAStartup@8'
debug/main.o:C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/asio/detail/impl/winsock_init.ipp:48: undefined reference to `WSACleanup@0'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\SIDController.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:\Qt\2010.05\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project SIDController (target: Desktop)
When executing build step 'Make'The problem remains. I am unable to successfully link boost_system and boost_filesystem. Thanks for pointing that out.
-
Another string which looks damn strange : you're compiling Qt with mingwin whereas you compiled boost with visual 10 (vc100 in library name).
Msvc and mingwin have different ABIs and can't be linekd together.
Either compile your Qt with Visual 2010 (you'll have to do it yourself) or compile boost with mingwin -
Hi golgobot,
In my opinion "this article":http://www.richelbilderbeek.nl/CppLinkErrorUndefinedReferenceToBoostSystemGet_system_categoryQtCreator.htm might be useful in your case. The suggested solution is to add the following line to your .pro file:
@LIBS += -lboost_system@
Cheers,
Leon -
Leon:
He's already got it (last -l, slightly differently formatted to take into account library):
@win32: LIBS += -L$$PWD/../../../libs/boost_1_44/stage/lib/ -llibboost_filesystem-vc100-mt -llibboost_system-vc100-mt@ -
[quote author="florent.revelut" date="1304326427"]Leon:
He's already got it (last -l, slightly differently formatted to take into account library):
@win32: LIBS += -L$$PWD/../../../libs/boost_1_44/stage/lib/ -llibboost_filesystem-vc100-mt -llibboost_system-vc100-mt@[/quote]May be the "lib" part in the name should be removed as "suggested in similar topic in stackoverflow":http://stackoverflow.com/questions/2958137/cannot-not-find-library-files-in-eclipse-cdt
Cheers,
Leon -
oh, true... It always confuse me between visual and gcc, which sometime truncate names differently. At least, trying is cheap !
-
Thanks everyone. I started building boost using mingw before I went to work today. It should be done when I get home. I'll try that out and see if that works!
One last thing. Does anyone know the difference between libboost_system and boost_system? Is one static and the other dynamic?
-
some linkers (especially gnu) removes lib at the beginning of file and extension (.a usually). This tradition comes from unix world, it's not followed extensively in windows world (I don't think msvc acts like that). Basically, using gnu ld (thus mingwin), to link a lib named libtoto.a, you would use -ltoto
-
[quote author="golgobot" date="1304354643"]
One last thing. Does anyone know the difference between libboost_system and boost_system? Is one static and the other dynamic? [/quote]This is a "qmake specific feature":http://doc.qt.nokia.com/latest/qmake-project-files.html#declaring-qt-libraries The familiar Unix-style notation for specifying libraries and paths can be used.
[quote author="florent.revelut" date="1304356117"]Basically, using gnu ld (thus mingwin), to link a lib named libtoto.a, you would use -ltoto
[/quote]
Excellent example :)
-
Ok so I rebuild boost libraries using mingw. From my boost root I ran the command
@
bjam.exe --toolset=gcc --build-type=complete
@This rebuilt the boost libraries using mingw. I ended up with a lot of libraries with ".a" extensions, the most important of which are libboost_system-mgw44-mt-1_44.a and libboost_filesystem-mgw44-mt-1_44.a. These are the two I want to link. My lib-includes in my .pro file looks like this below (the rest is the same as above)
@
win32: LIBS += -L$$PWD/../../../libs/boost_1_44/stage/lib/ -lboost_system-mgw44-mt-1_44 -lboost_filesystem-mgw44-mt-1_44INCLUDEPATH += $$PWD/../../../libs/boost_1_44/stage/lib
DEPENDPATH += $$PWD/../../../libs/boost_1_44/stage/lib
@the "lib" prefix is omitted, which is standard for including gcc libs.
When I compile I get the exact same error
bq.
C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:214: undefined reference toboost::system::generic_category()' C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:215: undefined reference to
boost::system::generic_category()'
C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:216: undefined reference toboost::system::system_category()' debug/serialsid.o:C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/system/error_code.hpp:211: undefined reference to
boost::system::system_category()'
debug/serialsid.o:C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/asio/detail/impl/winsock_init.ipp:39: undefined reference toWSAStartup@8' debug/serialsid.o:C:\workspaces\qt\SIDController-build-desktop/../../../libs/boost_1_44/boost/asio/detail/impl/winsock_init.ipp:48: undefined reference to
WSACleanup@0'
collect2: ld returned 1 exit statusAfter some more searching online I found a "post":http://stackoverflow.com/questions/1814548/boostsystem-category-defined-but-not-used that suggested I put this define statement
@
#ifndef BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED 1
#endif
@Before my include. I ran the build and now I get only one error (and lots of warnings, but let's ignore those for now)
bq.
......\libs\boost_1_44/boost/asio/error.hpp: In function 'const boost::system::error_category& boost::asio::error::get_system_category()':
......\libs\boost_1_44/boost/asio/error.hpp:220: error: 'get_system_category' is not a member of 'boost::system'I tried Googling that error, but came up with nothing. So I don't really feel closer to a solution. Just more confused than ever before. I look forward to seeing if anyone can help solve this mystery :)
-
The linker is sensitive to the order in which you link : you must link file_system, then system. Basically, file_system relies on system, this latter must appear after on the command line.
Could you please paste the exact command line that make is running ? Seems strange that it doesn't work...
-
The actual command that it is running is
bq. g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -Wl,-subsystem,console -mthreads -Wl -o release\SIDController.exe release/main.o -L"c:\Qt\2010.05\qt\lib" -LC:/workspaces/qt/SIDController/../../../libs/boost_1_44/stage/lib/ -lboost_filesystem-mgw44-mt-1_44 -lboost_system-mgw44-mt-1_44 -lQtGui4 -lQtCore4
It seems to be including the libraries for linking. I also switched the order of the libraries so boost_filesystem was first
-
And here is the complete output after a clean, then rebuild. Presented in two parts cause the max char limit for a post is 6000. This is easily reproducible using main.cpp shown at the beginning of the post in Windows 7 on a 64 bit processor. Could there be a 32 vs 64 bit issue?
bq. Running build steps for project SIDController...
Starting: "C:Qtqtcreator-2.1.84mingwbinmingw32-make.exe" clean
C:/Qt/qtcreator-2.1.84/mingw/bin/mingw32-make -f Makefile.Release clean
mingw32-make[1]: Entering directoryC:/workspaces/qt/SIDController-build-desktop' del releasemain.o mingw32-make[1]: Leaving directory
C:/workspaces/qt/SIDController-build-desktop'
C:/Qt/qtcreator-2.1.84/mingw/bin/mingw32-make -f Makefile.Debug clean
mingw32-make[1]: Entering directoryC:/workspaces/qt/SIDController-build-desktop' del debugmain.o mingw32-make[1]: Leaving directory
C:/workspaces/qt/SIDController-build-desktop'
Could Not Find C:workspacesqtSIDController-build-desktopreleasemain.o
Could Not Find C:workspacesqtSIDController-build-desktopdebugmain.o
The process "C:Qtqtcreator-2.1.84mingwbinmingw32-make.exe" exited normally.
Starting: "c:qt2010.05qtbinqmake.exe" C:workspacesqtSIDControllerSIDController.pro -r -spec win32-g++ "CONFIG+=release"
The process "c:qt2010.05qtbinqmake.exe" exited normally.
Starting: "C:Qtqtcreator-2.1.84mingwbinmingw32-make.exe"
C:/Qt/qtcreator-2.1.84/mingw/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory `C:/workspaces/qt/SIDController-build-desktop'
g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"......Qt2010.05qtincludeQtCore" -I"......Qt2010.05qtincludeQtGui" -I"......Qt2010.05qtinclude" -I"......libsboost_1_44" -I"......libsboost_1_44stagelib" -I"......Qt2010.05qtincludeActiveQt" -I"release" -I"..SIDController" -I"." -I"......Qt2010.05qtmkspecswin32-g++" -o releasemain.o ..SIDControllermain.cpp
In file included from ......libsboost_1_44/boost/asio/basic_datagram_socket.hpp:18,
from ......libsboost_1_44/boost/asio.hpp:20,
from ..SIDControllermain.cpp:3:
......libsboost_1_44/boost/asio/detail/config.hpp:59:5: warning: #warning Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately.
......libsboost_1_44/boost/asio/detail/config.hpp:60:5: warning: #warning For example, add -D_WIN32_WINNT=0x0501 to the compiler command line.
......libsboost_1_44/boost/asio/detail/config.hpp:61:5: warning: #warning Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
In file included from ......libsboost_1_44/boost/asio/detail/win_iocp_handle_service.hpp:281,
from ......libsboost_1_44/boost/asio/detail/win_iocp_serial_port_service.hpp:26,
from ......libsboost_1_44/boost/asio/serial_port_service.hpp:26,
from ......libsboost_1_44/boost/asio/basic_serial_port.hpp:29,
from ......libsboost_1_44/boost/asio.hpp:24,
from ..SIDControllermain.cpp:3:
......libsboost_1_44/boost/asio/detail/impl/win_iocp_handle_service.ipp: In constructor 'boost::asio::detail::win_iocp_handle_service::overlapped_wrapper::overlapped_wrapper(boost::system::error_code&)':
......libsboost_1_44/boost/asio/detail/impl/win_iocp_handle_service.ipp:49: warning: dereferencing type-punned pointer will break strict-aliasing rules
In file included from ......libsboost_1_44/boost/asio/ip/address_v6.hpp:227,
from ......libsboost_1_44/boost/asio/ip/address.hpp:22,
from ......libsboost_1_44/boost/asio.hpp:46,
from ..SIDControllermain.cpp:3:
......libsboost_1_44/boost/asio/ip/impl/address_v6.ipp: In constructor 'boost::asio::ip::address_v6::address_v6()':
......libsboost_1_44/boost/asio/ip/impl/address_v6.ipp:37: warning: missing braces around initializer for 'in6_addr::<anonymous union>'
......libsboost_1_44/boost/asio/ip/impl/address_v6.ipp:37: warning: missing braces around initializer for 'u_char [16]'
......libsboost_1_44/boost/asio/ip/impl/address_v6.ipp: In static member function 'static boost::asio::ip::address_v6 boost::asio::ip::address_v6::loopback()':
......libsboost_1_44/boost/asio/ip/impl/address_v6.ipp:259: warning: missing braces around initializer for 'in6_addr::<anonymous union>'
......libsboost_1_44/boost/asio/ip/impl/address_v6.ipp:259: warning: missing braces around initializer for 'u_char [16]'
In file included from ......libsboost_1_44/boost/asio/ip/detail/endpoint.hpp:139,
from ......libsboost_1_44/boost/asio/ip/basic_endpoint.hpp:20,
from ......libsboost_1_44/boost/asio.hpp:49,
from ..SIDControllermain.cpp:3:
......libsboost_1_44/boost/asio/ip/detail/impl/endpoint.ipp: In constructor 'boost::asio::ip::detail::endpoint::endpoint(int, short unsigned int)':
......libsboost_1_44/boost/asio/ip/detail/impl/endpoint.ipp:60: warning: missing braces around initializer for 'in6_addr::<anonymous union>'
......libsboost_1_44/boost/asio/ip/detail/impl/endpoint.ipp:60: warning: missing braces around initializer for 'u_char [16]' -
Part 2
bq. g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -Wl,-subsystem,console -mthreads -Wl -o releaseSIDController.exe release/main.o -L"c:Qt2010.05qtlib" -LC:/workspaces/qt/SIDController/../../../libs/boost_1_44/stage/lib/ -lboost_filesystem-mgw44-mt-1_44 -lboost_system-mgw44-mt-1_44 -lQtGui4 -lQtCore4
mingw32-make[1]: Leaving directoryC:/workspaces/qt/SIDController-build-desktop' release/main.o:main.cpp:(.text+0xda): undefined reference to
WSAStartup@8'
release/main.o:main.cpp:(.text+0xff): undefined reference toboost::system::generic_category()' release/main.o:main.cpp:(.text+0x109): undefined reference to
boost::system::generic_category()'
release/main.o:main.cpp:(.text+0x113): undefined reference toboost::system::system_category()' release/main.o:main.cpp:(.text+0x138): undefined reference to
boost::system::system_category()'
release/main.o:main.cpp:(.text+0x142): undefined reference toboost::system::system_category()' release/main.o:main.cpp:(.text+0x14c): undefined reference to
boost::system::system_category()'
release/main.o:main.cpp:(.text+0xa6): undefined reference toWSACleanup@0' release/main.o:main.cpp:(.text$_ZN5boost4asio6detail18win_tss_ptr_createEv[boost::asio::detail::win_tss_ptr_create()]+0x28): undefined reference to
boost::system::system_category()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [releaseSIDController.exe] Error 1
mingw32-make: *** [release] Error 2
The process "C:Qtqtcreator-2.1.84mingwbinmingw32-make.exe" exited with code 2.
Error while building project SIDController (target: Desktop)
When executing build step 'Make