Results 1 to 13 of 13

Thread: Boost: use it with Qt

  1. #1
    Join Date
    Jul 2010
    Posts
    13
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Boost: use it with Qt

    I cannot express how much time I've wasted over the last few weeks trying to get shit work with boost.

    Anyway, I'm trying to setup boost with Qt Creator right now, and I'm having linking issues.

    I've built my boost libraries for MinGW using:
    Qt Code:
    1. b2 --build-dir=build toolset=gcc --build-type=complete stagegcc
    To copy to clipboard, switch view to plain text mode 

    Now, I've added the following lines to my .pro:
    Qt Code:
    1. LIBS += -L"c:/boost_1_47_0/stagegcc/lib/"
    2. INCLUDEPATH += c:/boost_1_47_0/
    3. DEPENDPATH += c:/boost_1_47_0/
    To copy to clipboard, switch view to plain text mode 

    I'm using boost's ASIO library, which needs boost::system library
    when I try to compile my project I get the error:
    Qt Code:
    1. undefined reference to 'boost::system::generic_category()'
    To copy to clipboard, switch view to plain text mode 

    I've read several threads about how to get boost to work with Qt, but none of them helped so far.
    Also, I'm relatively new with Qt, last time I used it was 2 years ago for one project, so please be detailed in your instructions.

    I HATE boost right now.
    No success at all configuring it with Code::Blocks
    Managed to make it work with MSVC just to discover that it doesn't work with c++/cli so I cannot make any GUIs.

    Thank you

  2. #2
    Join Date
    Sep 2010
    Location
    Nagpur, India
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Boost: use it with Qt

    I too faced same problem couple of years ago while working on application using Qt and boost together.

    I worked by defining QT_NO_KEYWORDS macro (this will prohibit using Qt's signals and slots keywords which clashes with Boost) and then used Q_SIGNALS, Q_SLOT instead of Qt's signals and slots keywords while declaring in header file. You
    http://www.boost.org/doc/libs/1_49_0...gnals/s04.html

    Hope that helps.

    Jainish

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Boost: use it with Qt

    You are not linking against boost, you just told your compiler where to look for it but you didn't tell it to actually look for it. Add a LIBS += -l<libname> entry to your project file. By the way... What Boost ASIO does, Qt already does. So maybe it's easier to just port your code to Qt to get rid of the additional dependency.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jul 2010
    Posts
    13
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Boost: use it with Qt

    Thanks for the replies,

    I've added:
    LIBS += -lboost_system-mgw46-mt-1_47\
    -lboost_thread-mgw46-mt-1_47

    and
    #define BOOST_THREAD_USE_LIB
    to my source file

    Now I simply get "collect2: ld returned 1 exit status", no details...
    This is bad

    I'm slowly considering the option of dropping boost altogether now...

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Boost: use it with Qt

    You surely get more than this obscure message.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jul 2010
    Posts
    13
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Boost: use it with Qt

    I wish I did...

    But no, there's only 1 line and it is what I wrote. I've seen that before with gcc/g++.

    Perhaps I'm not linking the right libraries or I forgot to do some cryptic define?
    I'm really not sure which particular libraries I should be linking... every library has different versions, and while I checked the help about what they mean, I am still unsure. In any case I tried different variations and it is always the same message. If I omit to include one of those libraries I get the usual "undefined reference to xxxx" message.


    Added after 44 minutes:


    Well, I switched to the compile tab, it did effectively write more info there
    Qt Code:
    1. "undefined reference to `WSAStartup@8'
    To copy to clipboard, switch view to plain text mode 
    I googled that and the fix was to add a winsocket library, "-lws2_32".
    Now everything compiles fine, but I get a runtime error "0xc0000139", which I again googled and it means "DLL not found"
    Now I don't yet know which DLL is it complaining about. I assume it is a boost related one, since QT didn't give any troubles before I added the boost related source file.

    At least there seems to be some progress...

    EDIT:
    Well, I tried to exec the generated .exe file directly from windows explorer, and it says QtCored4.dll is missing.
    It seems like it does this for any qt generated program when I try to execute it directly by double-clicking the exe file, even if the program runs fine when executed through the IDE.
    This makes it hard to find which dll my boost program is complaining about.
    Last edited by Handi; 27th March 2012 at 23:39.

  7. #7
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Boost: use it with Qt

    Quote Originally Posted by Handi View Post
    [I]
    Well, I tried to exec the generated .exe file directly from windows explorer, and it says QtCored4.dll is missing.
    It seems like it does this for any qt generated program when I try to execute it directly by double-clicking the exe file, even if the program runs fine when executed through the IDE.
    Hi, this is probably because the QtCored4.dll is not in the standard search path for libraries. Windows looks for DLLs in some standard system directories and also in the directory where the exe is placed. You could resolve your error by copying the QtCored4.dll to the directory with the exe.

    Ginsengelf

  8. #8
    Join Date
    Jul 2010
    Posts
    13
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Boost: use it with Qt

    Seems like it creates all sorts of problems when I copy-paste Qcored4.dll in the folder. It then asks for 2 other dlls. When I copy those in the build folder, I get some weird error such as "The procedure entry point _Z11qt_assert_xPKcS0_S0_i could not be located in the dynamic link library QtCored4.dll". And that's for an application that actually WORKS in Qt... so I didn't even dare trying that with my boost program.

    Anyway, I gave up on boost. I ended up using QextSerialPort, it seems like it works well with the SPP service through bluetooth.
    I think I've spent more time trying to get boost to work with different IDEs than actual work.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Boost: use it with Qt

    This is kind of basic Windows programming knowledge. All required DLLs need to be available for the system linker to find them. You can do that by placing them in the same directory as the executable or putting them into %PATH%. The DLLs you need are the ones the application has been built against and I'm not talking about the file names but the files themselves. So you can't copy an arbitrary QtCored4.dll, you have to copy the one your compiler used. The same goes for any other library used by your application.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    Handi (1st April 2012)

  11. #10
    Join Date
    Jul 2010
    Posts
    13
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Boost: use it with Qt

    Thanks, I appreciate the help wysota.

    Unfortunately I do not have the privilege of having basic windows programming knowledge.
    I am not a software engineer, and all my programming knowledge is mostly language depended, not so much info about given environments.

    Anyway, I added my qt/bin directory and boost libs directory to the path, now it looks like everything compiles and executes!
    The only problem is that my boost program executes only when I double click the exe from windows explorer, and still returns the dll not found when ran from QtCreator.
    Did I forget to add something in my .pro file?

    This is what I added to path:
    Qt Code:
    1. C:\Qt\2010.04\qt\bin;C:\boost_1_47_0\stagegcc\lib
    To copy to clipboard, switch view to plain text mode 

    This is my .pro file:
    Qt Code:
    1. QT += core gui
    2.  
    3. TARGET = imugui1
    4. TEMPLATE = app
    5.  
    6. SOURCES += main.cpp\
    7. mainwindow.cpp \
    8. btserial.cpp
    9.  
    10. HEADERS += mainwindow.h \
    11. btserial.h
    12.  
    13. FORMS += mainwindow.ui
    14.  
    15. LIBS += -L"c:/boost_1_47_0/stagegcc/lib/"
    16. LIBS += -lboost_system-mgw46-mt-1_47 \
    17. -lboost_thread-mgw46-mt-1_47 \
    18. -lws2_32
    19.  
    20. INCLUDEPATH += c:/boost_1_47_0/
    21. DEPENDPATH += c:/boost_1_47_0/
    To copy to clipboard, switch view to plain text mode 

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Boost: use it with Qt

    Quote Originally Posted by Handi View Post
    Did I forget to add something in my .pro file?
    The .pro file has nothing to do with it. Its role ends when the program is compiled. What you are having problems with is executing the program. You need to make sure the required libraries can be found by the system linker when the application is ran. I'd suggest copying boost libraries to C:\Windows\system32 (or \system), then the linker should always find them.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #12
    Join Date
    Jul 2010
    Posts
    13
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Boost: use it with Qt

    Hmm that sounds like a weird workaround. Isn't there a better way to tell the linker where to look for libs?

  14. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Boost: use it with Qt

    Quote Originally Posted by Handi View Post
    Hmm that sounds like a weird workaround. Isn't there a better way to tell the linker where to look for libs?
    It is a weird workaround, however if you don't feel comfortable with the system, that's what I'd suggest. A better way is to make sure the linker can find the needed DLL by putting it in the same directory as the executable of the application or by adding the directory containing the DLL to system %PATH% (which is, from what you have said, what you have already tried, alas without success).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QT Roadmap considering Boost and C++0x
    By frank100 in forum Newbie
    Replies: 3
    Last Post: 19th January 2011, 20:59
  2. Qt and Boost in the same C++ program?
    By TriKri in forum Qt Programming
    Replies: 12
    Last Post: 9th May 2010, 22:58
  3. Howto use Qt with Boost ?
    By bilgenratte in forum Qt Programming
    Replies: 3
    Last Post: 1st October 2009, 14:12
  4. Boost libraries
    By steg90 in forum General Programming
    Replies: 26
    Last Post: 13th June 2007, 12:50
  5. boost::assign
    By Sivert in forum General Programming
    Replies: 0
    Last Post: 2nd May 2007, 00:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.