PDA

View Full Version : Qt and Bullet linking problem



Cruz
2nd January 2014, 16:38
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:



btRigidBody rigidBody = new btRigidBody(mass, &motionState, collisionShape, inertia);
btCollisionShape collisionShape = new btStaticPlaneShape(btVector3(0, 0, 1), 0);


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

ChrisW67
2nd January 2014, 21:21
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.

Cruz
2nd January 2014, 22:10
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.

ChrisW67
2nd January 2014, 22:16
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.

Cruz
2nd January 2014, 22:21
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.

ChrisW67
2nd January 2014, 22:49
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):


#if defined(BT_USE_DOUBLE_PRECISION)
typedef double btScalar;
//this number could be bigger in double precision
#define BT_LARGE_FLOAT 1e30
#else
typedef float btScalar;
//keep BT_LARGE_FLOAT*BT_LARGE_FLOAT < FLT_MAX
#define BT_LARGE_FLOAT 1e18f
#endif

I assume these are given to, or guessed by, CMake at library build time.

Is your "mass" variable declared:


float mass;
// or
btScalar mass;

Cruz
2nd January 2014, 23:16
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?

ChrisW67
2nd January 2014, 23:26
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 (http://www.dependencywalker.com/) on your exe/dll files to find what is depending on Qt5.

Cruz
2nd January 2014, 23:36
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?

ChrisW67
2nd January 2014, 23:37
Arrgghh! Timing! See my edit above

Cruz
3rd January 2014, 00:36
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.