Results 1 to 11 of 11

Thread: Qt and Bullet linking problem

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Qt and Bullet linking problem

    Hello!

    I'm struggling with a linker error. I don't fully understand the problem and I'm out of ideas what else to try. Can someone please give advice?

    The problem looks like this. I moved a Qt / Bullet Physics project to a new Win7 64 bit PC. Before I was developing it on a 32 bit Win7. The project compiles nicely there and runs without problems. I use the same Qt version 2010.05 on the new PC and I used the MinGW 4.4.0 that comes with it to compile the Bullet Physics library that is linked to my project. But when I build the project, I get linker errors like this:

    ./release\Joint.o:Joint.cpp:(.text+0x22e7): undefined reference to `btRigidBody::btRigidBody(float, btMotionState*, btCollisionShape*, btVector3 const&)'
    ./release\GroundPlane.o:GroundPlane.cpp:(.text+0x246 ): undefined reference to `btStaticPlaneShape::btStaticPlaneShape(btVector3 const&, float)'
    The corresponding lines in the source look like this:

    Qt Code:
    1. btRigidBody rigidBody = new btRigidBody(mass, &motionState, collisionShape, inertia);
    2. btCollisionShape collisionShape = new btStaticPlaneShape(btVector3(0, 0, 1), 0);
    To copy to clipboard, switch view to plain text mode 

    I don't think the problem is in the source though, since it compiles and links perfectly fine on the 32 bit system. And it's not like every call to the Bullet library produces a linker error. Only a very few pop up and strangely, all of them have a float parameter, where actually a btScalar (Bullet's on floating point) should be used. The main difference between the old and new environment is the bitness, so I suspect that the problem may be coming from there, but I have no idea what exactly it could be. Any ideas where to dig next?

    Thanks,
    Cruz

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt and Bullet linking problem

    I assume that these bt* classes are part of the Bullet library. That library needs to built and/or installed on the machine and the Qt project file LIBS variable set so the linker will find the library.

  3. #3
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt and Bullet linking problem

    Yes I did that. I compiled the Bullet library with the same MinGW version that I use to compile my project. LIBS is set and I'm sure it's correct. It must be something else.
    In fact, I tried setting a wrong LIBS on purpose and yes, in that case it showers linker errors from every place I access the Bullet library. Setting LIBS back to the correct value reduces the errors to a few, all of which have a float variable as an argument where in the Bullet documentation it should be a btScalar. I don't understand this part and I'm pretty sure it's related to the actual problem.
    Last edited by Cruz; 2nd January 2014 at 21:18.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt and Bullet linking problem

    It must be something else.
    Famous last words. The error message from your linker is explicit... it cannot find the library.

    Where is Bullet built and installed and what is the LIBS value in your PRO file.

  5. #5
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt and Bullet linking problem

    Bullet is in C:\usr\lib and the related part of my .pro looks like this:

    win32:LIBS += -Lc:/usr/lib
    win32:LIBS += -lBulletDynamics -lBulletCollision -lLinearMath

    The linker must find the library because it doesn't complain about every Bullet call, only a few selected ones. I edited my last post, maybe you didn't see that yet, and tried setting LIBS to a wrong value on purpose to check this.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt and Bullet linking problem

    I edited my last post, maybe you didn't see that yet, and tried setting LIBS to a wrong value on purpose to check this.
    Yep, you edited it after I posted.

    You are using the same (very old) 32-bit compiler on your 64-bit system. It should be generating the same 32-bit libs/exes for the same input. However, the definition of btScalar can map to either float or double depending on configuration switches (from btScalar.h):
    Qt Code:
    1. #if defined(BT_USE_DOUBLE_PRECISION)
    2. typedef double btScalar;
    3. //this number could be bigger in double precision
    4. #define BT_LARGE_FLOAT 1e30
    5. #else
    6. typedef float btScalar;
    7. //keep BT_LARGE_FLOAT*BT_LARGE_FLOAT < FLT_MAX
    8. #define BT_LARGE_FLOAT 1e18f
    9. #endif
    To copy to clipboard, switch view to plain text mode 
    I assume these are given to, or guessed by, CMake at library build time.

    Is your "mass" variable declared:
    Qt Code:
    1. float mass;
    2. // or
    3. btScalar mass;
    To copy to clipboard, switch view to plain text mode 

  7. The following user says thank you to ChrisW67 for this useful post:

    Cruz (2nd January 2014)

  8. #7
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt and Bullet linking problem

    Oh you are so good! mass is declared to be a btScalar. But yes there is a CMake flag for float or double precision. I set it to float precision and recompiled Bullet just now and the linker errors are gone! The application still crashes when I start it, so something is still not quite right, but the linker problem seems to be solved now. Thanks a lot for your effort mate! You really helped me along.


    Added after 16 minutes:


    Ok the next step is tough too. The application doesn't start, because it's looking for Qt5Cored.dll. Qt 5! I have no idea where this is coming from. While trying to figure out the linker problem, I have had Qt 5.2 installed at some point. But I uninstalled all Qt versions and reinstalled the same Qt 2010.05 that I was using on my old system. I'm compiling on the command line first calling qmake and then mingw32-make debug. I'm using the command line that comes with the Qt SDK that sets the environment up automatically. Where else is the Qt version set?
    Last edited by Cruz; 2nd January 2014 at 22:16.

  9. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt and Bullet linking problem

    Make sure you clean out your build (Makefiles, *.o, *.a, *.exe etc) and use the qmake from the Qt4.4 you have: it should generate the correct Makefile and link the Qt4 libraries. If your Makefile was written by a Qt5 qmake then it, and any object file built with it, will have Qt5 references.

    Edit:
    It's also possible CMake has cached references to Qt5 from an earlier build of the library.
    You can use Dependency Walker on your exe/dll files to find what is depending on Qt5.
    Last edited by ChrisW67; 2nd January 2014 at 22:37.

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

    Cruz (2nd January 2014)

  11. #9
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt and Bullet linking problem

    No, that didn't help. I did that several times already but I did it again just to make sure. I deleted alle Makefile files and called qmake again. I have only one qmake so it must be the right one. The "where" command confirms this. Then I clean, build and call the .exe file and I get the same error message. It's looking for a Qt 5 dll. I imagine that reinstalling the whole OS from scratch would help, but maybe there is a shorter way?

  12. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt and Bullet linking problem

    Arrgghh! Timing! See my edit above

  13. #11
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt and Bullet linking problem

    I didn't need the Dependency Walker to guess that I compiled the only qt based library my project depends on with Qt 5. Recompiled it with Qt 4 and solved a number of other missing DLLs and there you go! It starts and works and it's beautiful! Thank you so much for your help.

Similar Threads

  1. Qt linking problem
    By LovesTha in forum Newbie
    Replies: 3
    Last Post: 30th March 2009, 23:31
  2. Linking problem on Mac os x 10.4
    By maverick_pol in forum General Programming
    Replies: 0
    Last Post: 6th January 2008, 14:09
  3. Linking problem
    By prosass in forum Newbie
    Replies: 3
    Last Post: 2nd March 2007, 12:22
  4. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 21:41
  5. linking problem
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2006, 14:30

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.