Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking issue with BulletExample #2

Closed
severin-lemaignan opened this issue Sep 18, 2013 · 5 comments
Closed

Linking issue with BulletExample #2

severin-lemaignan opened this issue Sep 18, 2013 · 5 comments

Comments

@severin-lemaignan
Copy link

Bullet example fail to link with the following error:

Linking CXX executable bullet
CMakeFiles/bullet.dir/BulletExample.o: In function `Magnum::SceneGraph::AbstractFeature<3u, float>::AbstractFeature<Magnum::SceneGraph::Object<Magnum::SceneGraph::BasicMatrixTransformation3D<float> >, void>(Magnum::SceneGraph::Object<Magnum::SceneGraph::BasicMatrixTransformation3D<float> >&)':
BulletExample.cpp:(.text._ZN6Magnum10SceneGraph15AbstractFeatureILj3EfEC2INS0_6ObjectINS0_27BasicMatrixTransformation3DIfEEEEvEERT_[_ZN6Magnum10SceneGraph15AbstractFeatureILj3EfEC5INS0_6ObjectINS0_27BasicMatrixTransformation3DIfEEEEvEERT_]+0x1f): undefined reference to `Magnum::SceneGraph::AbstractFeature<3u, float>::AbstractFeature(Magnum::SceneGraph::AbstractObject<3u, float>&)'
collect2: error: ld returned 1 exit status

Compiler (GCC 4.7) was called like that:

/usr/bin/c++    -std=c++0x -Wall -Wextra -Wold-style-cast -Winit-self -Werror=return-type -Wmissing-declarations -pedantic -fvisibility=hidden -Wzero-as-null-pointer-constant -Wdouble-promotion    CMakeFiles/bullet.dir/BulletExample.o  -o bullet  -L/usr/local/lib -rdynamic /usr/local/lib/libMagnum.so /usr/local/lib/libCorradeUtility.so /usr/local/lib/libCorradePluginManager.so /usr/local/lib/libCorradeUtility.so -ldl -lGL /usr/local/lib/libMagnumBulletIntegration.so -lBulletDynamics -lBulletCollision -lLinearMath -lBulletSoftBody /usr/local/lib/libMagnumDebugTools.so /usr/local/lib/libMagnumSceneGraph.so /usr/local/lib/libMagnumShaders.so /usr/local/lib/libMagnumShapes.so /usr/local/lib/libMagnumGlutApplication.a -lglut -lXmu -lXi /usr/local/lib/libCorradePluginManager.so -ldl -lGL /usr/local/lib/libMagnumBulletIntegration.so -lBulletDynamics -lBulletCollision -lLinearMath -lBulletSoftBody /usr/local/lib/libMagnumDebugTools.so /usr/local/lib/libMagnumSceneGraph.so /usr/local/lib/libMagnumShaders.so /usr/local/lib/libMagnumShapes.so /usr/local/lib/libMagnumGlutApplication.a -lglut -lXmu -lXi -Wl,-rpath,/usr/local/lib 

Looks similar to magnum-bootstrap issue 3

EDIT: the issue was that libmagnum was compiled with clang with the sample was compiled with gcc. Using the same compiler for both solved the issue.

@mosra
Copy link
Owner

mosra commented Sep 18, 2013

Sorry, can't reproduce with GCC 4.7.3. The linking command is the following (I installed Magnum into /usr, but everything else seems to be the same):

/usr/bin/g++-4.7    -std=c++0x -Wall -Wextra -Wold-style-cast -Winit-self -Werror=return-type -Wmissing-declarations -pedantic -fvisibility=hidden -Wzero-as-null-pointer-constant -Wdouble-promotion    CMakeFiles/bullet.dir/BulletExample.cpp.o  -o bullet -rdynamic -lMagnum -lCorradeUtility -lCorradePluginManager -lCorradeUtility -ldl -lGL -lMagnumBulletIntegration -lBulletDynamics -lBulletCollision -lLinearMath -lBulletSoftBody -lMagnumDebugTools -lMagnumSceneGraph -lMagnumShaders -lMagnumShapes -Wl,-Bstatic -lMagnumGlutApplication -Wl,-Bdynamic -lglut -lXmu -lXi -lCorradePluginManager -ldl -lGL -lMagnumBulletIntegration -lBulletDynamics -lBulletCollision -lLinearMath -lBulletSoftBody -lMagnumDebugTools -lMagnumSceneGraph -lMagnumShaders -lMagnumShapes -Wl,-Bstatic -lMagnumGlutApplication -Wl,-Bdynamic -lglut -lXmu -lXi

First four lines of nm /usr/lib/libMagnumSceneGraph.so | grep AbstractFeature | grep AbstractObject indicate that the symbol is present in the library:

000000000001d960 W _ZN6Magnum10SceneGraph15AbstractFeatureILj2EfEC1ERNS0_14AbstractObjectILj2EfEE
000000000001d960 W _ZN6Magnum10SceneGraph15AbstractFeatureILj2EfEC2ERNS0_14AbstractObjectILj2EfEE
000000000001dd20 W _ZN6Magnum10SceneGraph15AbstractFeatureILj3EfEC1ERNS0_14AbstractObjectILj3EfEE
000000000001dd20 W _ZN6Magnum10SceneGraph15AbstractFeatureILj3EfEC2ERNS0_14AbstractObjectILj3EfEE
...

@severin-lemaignan
Copy link
Author

Yes, strangely enough, it seems that the symbols are defined for me as well:

$ nm /usr/local/lib/libMagnumSceneGraph.so | grep AbstractFeature | grep AbstractObject
0000000000012350 W _ZN6Magnum10SceneGraph15AbstractFeatureILj2EfEC2ERNS0_14AbstractObjectILj2EfEE
0000000000012660 W _ZN6Magnum10SceneGraph15AbstractFeatureILj3EfEC2ERNS0_14AbstractObjectILj3EfEE
[...]

I've tried to change the order of the lib in the compiler cmd line, without much success...

Do you have a clue why the symbols were listed twice each in your case?

@severin-lemaignan
Copy link
Author

Well, the only difference I see between your mangled symbols is C2 and C1 (+ the obvious 2u/3u template specialization).

This distinction between C1 and C2 does not exist in my case (I've only the symbols with C2).

According to this spec, the distinction is:

<ctor-dtor-name> ::= C1 # complete object constructor
           ::= C2   # base object constructor

Does it makes somehow sense to you?

@mosra
Copy link
Owner

mosra commented Sep 18, 2013

As far as I know, this has someting to do with template instantiation and weak symbols -- the template can be instantiated (and added to symbol table) more than once without error.

I compiled Magnum with GCC 4.7, which added the symbols twice. Now I tried to build it with Clang and it has the symbol only once, just like in your case. I conclude that this is some weird compiler incompatibility -- try to build the examples with Clang too (or build Magnum with GCC 4.7).

@severin-lemaignan
Copy link
Author

Well spotted! It indeed fixes the link error, and the demo runs fine!

Is it something we should check & enforce (samples/bootstraps use the same compiler as the main lib)? it may not be a very common issue, though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants