Qt Creator, linked boost library and debug



  • Hello.

    I have found a strange problem with Qt Creator and boost library.
    I have a simple "Hello World!" program in the Qt Creator. So far so good. But I need to use the boost::filesystem library.
    So I add:

    @
    #include <boost/filesystem.hpp>
    @

    to the source code and

    @
    INCLUDEPATH += C:/boost
    LIBS += C:/boost/stage/lib/libboost_filesystem-mgw45-mt-d-1_46_1.a
    LIBS += C:/boost/stage/lib/libboost_system-mgw45-mt-d-1_46_1.a
    @

    to the .pro file

    Building the application for the "release" target is OK, no errors. Result executable executes and works well.
    But for the "debug" target it doesn't. I got the error:
    The process could not be started: %1 is not a valid Win32 application.
    Debugging can be started but it ignores all breakpoints and terminates immediately.

    Don't you know what could case this problem?
    If I don't have #include <boost/filesystem.hpp> in the source code, the "debug" executable can be executed, but when I include boost/filesystem, it immediately becomes invalid win32 application. However "release" executable works well in both cases.

    Thank you.

    P.S.
    I tried to create the same simple application in Code::Blocks, just to test whether included boost libraries are compiled correctly and yes, there's no problem with both release and debug build targets, all works fine. So it doesn't seem to be a problem with boost libraries.

    I'm using Qt SDK 1.1, Qt Creator 2.2 installed later, Windows 7 Ultimate x64

    [EDIT: code formatting, please wrap in @-tags, Volker]


  • Moderators

    That looks a lot like some stale files being left behind from one build being used in the new one.

    Did you clean out the build directory after switching to debug or did you use different shadow build directories for debug and release?

    Doing a clean rebuild should fix this.



  • Thanks for the answer.

    Unfortunately this is not the problem. I have cleaned the project, then I have deleted the entire directory boosttest-build-desktop and then "debug" built again - and the same problem occured.
    What more, just commenting out the line "#include <boost/filesystem.hpp>" and "rebuild project" makes the .exe file executable in "debug" target again. So there IS something wrong with linking but I have no idea what it can be.

    Thanks.



  • On windows you're using .dll, not .a.

    So what's you compiler ? (mingw 4.5 ?)

    Don't use QTCreator 2.2 wich is not delivered with Qt SDK 1.1

    try :

    -L : this is a path

    -l : is a file without extension (.a or .lib is added)

    \ : continue on following line

    $$quote(..) : useful for path like 'c:/program files'

    @DEFINES += BOOST_ALL_DYN_LINK # for using dynamic libraries

    LIBS += -L$$quote(C:/boost/stage/lib) \
    -llibboost_filesystem-mgw45-mt-d-1_46_1
    -llibboost_system-mgw45-mt-d-1_46_1@

    eventually make separate config for debug and release
    @
    CONFIG(debug, debug|release) {
    LIBS += -L$$quote(C:/boost/stage/lib) \
    -llibboost_filesystem-mgw45-mt-d-1_46_1
    -llibboost_system-mgw45-mt-d-1_46_1
    } else {
    LIBS += -L$$quote(C:/boost/stage/lib) \
    -llibboost_filesystem-mgw45-mt-1_46_1
    -llibboost_system-mgw45-mt-1_46_1
    }
    @



  • Hi.

    Thank you for your reply.
    You know what? You have solved my problem with one sentence:
    Don’t use QTCreator 2.2 wich is not delivered with Qt SDK 1.1
    That is, it works with Qt Creator 2.1 supplied with Qt SDK, but not with QTC 2.2. (Maybe different version of MinGW coming with this new version...?)

    I didn't even had to change LIBS += settings in the .pro file.
    And about .dll - they are used for dynamic linking, but I want statick link, I want to produce single .exe file.

    Thank you very much for your help.


  • Moderators

    Well, great that this helps for now, but the SDK will eventually upgrade to Qt Creator 2.2 and then you will have the same issue. I would really appreciate getting this nailed down:-)

    Can you make your example available to us? How did you build it in codeblocks? Did you use a different build system or did you reuse the qmake .pro-file you had? Did codeblocks and creator use the same mingw?



  • Hi.
    Well, it seems there's really problem with MinGW versions I have installed, you're right.

    My default MinGW installation (C:\MinGW) is version 4.5.0

    Code::Blocks uses this default installation, so it's running on 4.5.0

    Compilation of boost libraries (bootstrap, bjam) used this default MinGW too, it's compiled with 4.5.0

    But QtSDK comes with its own MinGW - 4.4.0

    And Qt Creator 2.2 also comes with its own MinGW - also 4.4.0

    In "Build Settings" of both Qt Creators (2.1 from QtSDK and standalone 2.2) I can see the same settings in Qt version - "Qt 4.7.3 for Desktop - MinGW 4.4 (Qt SDK)," referencing "c:\qtsdk\desktop\qt\4.7.3\mingw\bin\qmake.exe" directory.

    So I have boost libraries compiled with MinGW 4.5.0, but Qt Creator uses its own 4.4.0 for my program. It can be the problem, I see.
    But why release works fine and only debug fails in Qt Creator 2.2?
    And why Qt Creator 2.1 releases and debugs with no problem - especially if both 2.1 and 2.2 use the same Qt from QtSDK?

    For Code::Blocks I created a new project from scratch - in fact it creates a "Hello World" main.cpp automatically when new project is created, so all I had to do was to add libraries to linker, includes to compiler and one line of code: #include <boost/filesystem.hpp>

    Thank you.


  • Moderators

    Could you please try setting up mingw 4.5 in Qt Creator? Go to Tools->Options->Tool chain and add a new mingw tool chain. Point it to the g++ of the mingw 4.5, rename the whole thing (click on the name in the table) and apply the whole thing.

    You should not be able to select that version to build your project. Does it work when building with the newer mingw?



  • Just few comments
    Qt Creator 2.2 work fine on windows xp/seven with Qt SDK 1.1

    install Visual C++ 2008 Express Edition (free, uncheck SQL serveur express if you don't have to use)

    install QtSDK 1.1 VS2008 (uncheck all about MinGW, check delete QtCreator previous settings)

    install QtCreator 2.2 (uncheck MinGW)

    Both Qt Creator 2.1/2.2 work fine (release and debug)



  • @Tobias Hunger:
    Oh yes, that's it. It works now.
    Qt Creator 2.1 probably choose the right MinGW by itself (I cannot check it, Tool Chain combobox is disabled in build settings there and no "Tool Chain" option in Tools/Options is present) but 2.2 set up its toolchain to QtSDK's MinGW 4.4.0.
    When I changed ToolChain to "MinGW (x86 32bit) - 4.5.0" in QTC 2.2, both release and debug builds started to work fine.

    Thank you very much, Tobias.



  • If you happen to change boost versions, this is perhaps more generic way of doing this:
    (define your environment variable pointing at boost-root, e.g. C:\boost_1_54_0)

    than, for gcc4.7.2 (e.g. from qt 5.0.2)
    in .pro file:

    @ INCLUDEPATH += $(BOOST_ROOT)
    BOOST = $(BOOST_ROOT)
    GCC_VER = system(gcc -dumpversion)
    COMPILER = gcc-mingw-$${GCC_VER}
    #dunno how to make mgw47 from gcc-mingw and 4.7.2 from here..
    COMPILER_SHORT = mgw47

    BOOST_SUFFIX = $${COMPILER_SHORT}-mt-${BOOST_VER}
    
    LIBS += -L$${BOOST}/stage/lib
    
    // now you can add your libraries, e.g.
    LIBS += -lboost_system-$${BOOST_SUFFIX}
    
    LIBS += -lboost_WHATEVER-$${BOOST_SUFFIX} // just change 'WHATEVER' to a valid lib name..@
    

    (obviously above is assuming you've compiled your boost with the same compiler, e.g.:

    @cd %BOOST_ROOT%;
    set PATH=C:\Qt\Qt5.0.2\Tools\MinGW\bin;%PATH%;
    boostrap gcc
    b2 --build-dir=/temp/build-boost toolset=gcc stage@

    if you're using boost_1_54, you'd better off defining following in your project-config.jam before the build:
    @using gcc : : :
    <cxxflags>-std=c++0x
    <cxxflags>"-include cmath"
    ;@

    etc..


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.