May 16, 2011

o.vencovsky o.vencovsky
Lab Rat
4 posts

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:

  1. #include <boost/filesystem.hpp>

to the source code and

  1. INCLUDEPATH += C:/boost
  2. LIBS += C:/boost/stage/lib/libboost_filesystem-mgw45-mt-d-1_46_1.a
  3. 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]

10 replies

May 16, 2011

Tobias Hunger Tobias Hunger
Hobby Entomologist
3373 posts

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.

May 16, 2011

o.vencovsky o.vencovsky
Lab Rat
4 posts

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.

May 17, 2011

gedd gedd
Lab Rat
36 posts

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 :

  1. -L : this is a path
  2. -l : is a file without extension (.a or .lib is added)
  3. \ : continue on following line
  4. $$quote(..) : useful for path like ‘c:/program files’

  1. DEFINES += BOOST_ALL_DYN_LINK  # for using dynamic libraries
  2.  
  3. LIBS += -L$$quote(C:/boost/stage/lib)  \
  4.            -llibboost_filesystem-mgw45-mt-d-1_46_1 \
  5.            -llibboost_system-mgw45-mt-d-1_46_1

eventually make separate config for debug and release

  1. CONFIG(debug, debug|release) {
  2. LIBS += -L$$quote(C:/boost/stage/lib)  \
  3.            -llibboost_filesystem-mgw45-mt-d-1_46_1 \
  4.            -llibboost_system-mgw45-mt-d-1_46_1
  5. } else {
  6. LIBS += -L$$quote(C:/boost/stage/lib)  \
  7.            -llibboost_filesystem-mgw45-mt-1_46_1 \
  8.            -llibboost_system-mgw45-mt-1_46_1
  9. }

 Signature 

Gedd

May 17, 2011

o.vencovsky o.vencovsky
Lab Rat
4 posts

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.

May 17, 2011

Tobias Hunger Tobias Hunger
Hobby Entomologist
3373 posts

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?

May 18, 2011

o.vencovsky o.vencovsky
Lab Rat
4 posts

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

  1. My default MinGW installation (C:\MinGW) is version 4.5.0
  2. Code::Blocks uses this default installation, so it’s running on 4.5.0
  3. Compilation of boost libraries (bootstrap, bjam) used this default MinGW too, it’s compiled with 4.5.0
  4. But QtSDK comes with its own MinGW – 4.4.0
  5. And Qt Creator 2.2 also comes with its own MinGW – also 4.4.0
  6. 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.

May 18, 2011

Tobias Hunger Tobias Hunger
Hobby Entomologist
3373 posts

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?

May 18, 2011

gedd gedd
Lab Rat
36 posts

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

  1. install Visual C++ 2008 Express Edition (free, uncheck SQL serveur express if you don’t have to use)
  2. install QtSDK 1.1 VS2008 (uncheck all about MinGW, check delete QtCreator previous settings)
  3. install QtCreator 2.2 (uncheck MinGW)

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

 Signature 

Gedd

May 18, 2011

o.vencovsky o.vencovsky
Lab Rat
4 posts

@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.

July 8, 2013

formiaczek formiaczek
Lab Rat
1 posts

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:

  1.     INCLUDEPATH +=  $(BOOST_ROOT)  
  2.     BOOST = $(BOOST_ROOT)
  3.     GCC_VER = system(gcc -dumpversion)
  4.     COMPILER = gcc-mingw-$${GCC_VER}
  5.     #dunno how to make mgw47 from gcc-mingw and 4.7.2 from here..
  6.     COMPILER_SHORT = mgw47
  7.  
  8.     BOOST_SUFFIX = $${COMPILER_SHORT}-mt-${BOOST_VER}
  9.  
  10.     LIBS += -L$${BOOST}/stage/lib
  11.  
  12.     // now you can add your libraries, e.g.
  13.     LIBS += -lboost_system-$${BOOST_SUFFIX}
  14.  
  15.     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.:

  1. cd %BOOST_ROOT%;
  2. set PATH=C:\Qt\Qt5.0.2\Tools\MinGW\bin;%PATH%;
  3. boostrap gcc
  4. 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:

  1. using gcc : : :
  2.      <cxxflags>-std=c++0x
  3.   <cxxflags>"-include cmath"
  4.     ;

etc..

 
  ‹‹ QT Creator and QWT AutoComplete?      Qt Creator and Building example widgets on embedded platforme ››

You must log in to post a reply. Not a member yet? Register here!