Link boost libraries to Qt

Apr 3, 2012 at 8:15pm
Hello . I'm starting a project in Qt , using Qt creator , and want to link boost.asio to my project but I've got some problems doing that .

Qt 4.7.4(32 bit)
Qt Creator 2.3.0
boost 1.49.0
MinGW 4.4
platform : Windows 7

I added these two lines to my .pro file :

INCLUDEPATH +=C:/Users/vahid/Downloads/boost_1_49_0/boost_1_49_0
LIBS +=-L"C:/Users/vahid/Downloads/boost_1_49_0/boost_1_49_0/stage/lib/" -llibboost_system-vc100-mt-1_49.lib

and I just included boost.asio and these issues were reported in Qt creator when building :
cannot find -llibboost_system-vc100-mt-1_49.lib
collect2: ld returned 1 exit status
Last edited on Apr 3, 2012 at 8:19pm
Apr 5, 2012 at 11:50am
Nobody knows ? :(
Apr 5, 2012 at 12:11pm
I don't know QT Creator. Usually you don't specify the lib used (just the path) since the name of the lib is determined in the boost header.

Does that boost libs exists?
Apr 5, 2012 at 12:43pm
Try this:


1
2
3
INCLUDEPATH += C:/Users/vahid/Downloads/boost_1_49_0/boost_1_49_0/
LIBS += -LC:/Users/vahid/Downloads/boost_1_49_0/boost_1_49_0/stage/lib/
LIBS += -llibboost_system-vc100-mt-1_49
Last edited on Apr 5, 2012 at 12:44pm
Apr 5, 2012 at 12:45pm
Have you built libboost_system-vc100-mt-1_49.lib or does it exist in the stage directory?
Apr 5, 2012 at 1:10pm
yes the library exists in stage/lib
I added those lines to my project and I have these errors when building :

In function `_static_initialization_and_destruction_0':
undefined reference to `boost::system::generic_category()'
undefined reference to `boost::system::generic_category()'
undefined reference to `boost::system::generic_category()'
undefined reference to `boost::system::generic_category()'
undefined reference to `WSAStartup@8'
undefined reference to `WSACleanup@0'
collect2: ld returned 1 exit status
Apr 5, 2012 at 1:12pm
the onliest code related to boost in my project is : #include <boost/asio>
should I add any other library ?
Apr 5, 2012 at 1:14pm
When you specify a library file name, you don't write its extension (.dll, .lib, .a,...). You should just write whether the linking is static or dynamic, and the extensions are found automatically.

Try getting your makefile to link statically to boost by:

 
CONFIG += static


BTW: It's way better if you use relative paths rather than absolute paths. It's not professional at all to write a whole absolute path to link your libraries. Try to put all 3rd-party libraries in a single folder parallel to your project source, and link to them with a relative path. That will make stuff easier for you. And don't use long file/folder names, so that you could avoid mistyping/misinterpreting stuff.
Last edited on Apr 5, 2012 at 1:17pm
Apr 5, 2012 at 1:16pm
I added CONFIG += static to my .pro file too , but again same errors.
Apr 5, 2012 at 1:25pm
could it be bacause of my minGW version ? it is 4.4 and maybe is old to use with boost 1.49 .
Apr 5, 2012 at 1:31pm
That you have to check in the documentation of boost. But I doubt it. It's very unlikely to be the reason.

I'll show you how I linked GSL (GNU Scientific Library) with a GUI project in Qt. Hope this helps:

1
2
3
4
5
6
7
8
9
10

DEPENDPATH += ../../libsrc/gsl/gsl-win-1.8
DEPENDPATH += ../../libsrc/gsl/gsl-win-1.8/lib
INCLUDEPATH += ../../libsrc/gsl/gsl-win-1.8/include

LIBS += -L../../libsrc/gsl/gsl-win-1.8/lib
LIBS += -L../../libsrc/gsl/gsl-win-1.8/bin
LIBS += -llibgsl
LIBS += -llibgslcblas


And in the directory, there are 2 files:

libgsl.dll
libgslcblas.dll

I hope you can extrapolate how to work this out in a similar way. :-)
Apr 5, 2012 at 1:42pm
Ah I'm sorry, in lib directory there are more files:

libgsl.a
libgsl
libgsl.dll.a
libgslcblas.a
libgslcblas
libgslcblas.dll.a

The others I mentioned are in the bin directory.
Apr 5, 2012 at 3:01pm
How did you compile boost? It's somewhat tricky to do this with mingw.

This libboost_system-vc100-mt-1_49 looks like as if it's build for visual c++
Apr 5, 2012 at 3:15pm
You'll need the build of boost that matches your build type and you'll need to ws2_32.lib.
Apr 5, 2012 at 3:21pm
coder777@
oh my God !! I think that is the point !!

I built them using these commands:
bootstrap
.\b2


according to what boost documentation says :

If you wish to build from source with Visual C++, you can use a simple build procedure described in this section. Open the command prompt and change your current directory to the Boost root directory. Then, type the following commands:

bootstrap
.\b2
--------------------------------------
How should I build them with minGW ??
Last edited on Apr 5, 2012 at 3:22pm
Apr 5, 2012 at 3:32pm
I dunno if this helps:
http://www.cleardefinition.com/page/Build_Boost_for_MinGW/

I just Googled it, there are quite a few interesting hits.
Apr 5, 2012 at 7:54pm
coder777 you are my hero :D

I finally made it .The problem was what coder777 noticed .my boost Binary libraries were built with visual c++ while it should have been built using minGW .

according to this documentation http://www.boost.org/doc/libs/1_49_0/more/getting_started/windows.html#id39 part (5.3.1 Install Boost.Build) I built libraries for minGW . In fact I invoke b2 with this command :

b2 toolset=gcc --build-type=complete stage

after building binaries I added these lines to my .pro file :

INCLUDEPATH +=C:/boost_1_49_0/boost_1_49_0
LIBS +=-LC:/boost_1_49_0/boost_1_49_0/stage/lib/
LIBS+=-llibboost_system-mgw46-1_49 -lws2_32

and everything run smoothly ;)
thanks everybody .
Topic archived. No new replies allowed.