Problem linking against installed bullet lib on Ubuntu

silwol
Posts: 4
Joined: Wed Dec 05, 2007 6:47 pm

Problem linking against installed bullet lib on Ubuntu

Post by silwol »

I compiled and installed bullet on my ubuntu gutsy box. For a small trial project, I wrote a simple Makefile which looks like this:
CXXFLAGS=-Wall
# ogre
CXXFLAGS+=`pkg-config OGRE --cflags`
LDFLAGS+=`pkg-config OGRE --libs`
# ois
CXXFLAGS+=`pkg-config OIS --cflags`
LDFLAGS+=`pkg-config OIS --libs`
# bullet
CXXFLAGS+=`pkg-config bullet --cflags`
LDFLAGS+=`pkg-config bullet --libs`

build: trial

trial: trial.o

clean:
rm -fR *.o *.so trial

rebuild: clean build
When I try to compile my trial program, I get the following output:
cc `pkg-config OGRE --libs` `pkg-config OIS --libs` `pkg-config bullet --libs` trial.o -o trial
trial.o: In function `btConvexShape::operator new(unsigned int)':
/usr/local/include/bullet/BulletCollision/CollisionShapes/btConvexShape.h:40: undefined reference to `btAlignedAllocInternal(unsigned int, int)'
trial.o: In function `btCollisionObject::operator new(unsigned int)':
/usr/local/include/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h:93: undefined reference to `btAlignedAllocInternal(unsigned int, int)'
trial.o: In function `btBoxShape':
/usr/local/include/bullet/BulletCollision/CollisionShapes/btBoxShape.h:86: undefined reference to `btPolyhedralConvexShape::btPolyhedralConvexShape()'
/usr/local/include/bullet/BulletCollision/CollisionShapes/btBoxShape.h:86: undefined reference to `vtable for btBoxShape'
trial.o: In function `btConvexShape::operator delete(void*)':
/usr/local/include/bullet/BulletCollision/CollisionShapes/btConvexShape.h:40: undefined reference to `btAlignedFreeInternal(void*)'
trial.o: In function `btCollisionObject::operator delete(void*)':
/usr/local/include/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h:93: undefined reference to `btAlignedFreeInternal(void*)'
trial.o: In function `TutorialApplication::createScene()':
/home/silwol/esd_sem01/pro/RoboSim3D/snippets/ogre-bullet/trial.h:104: undefined reference to `btRigidBody::btRigidBody(float, btMotionState*, btCollisionShape*, btVector3 const&, float, float, float, float)'
trial.o: In function `ExampleApplication::createSimulator()':
/home/silwol/esd_sem01/pro/RoboSim3D/snippets/ogre-bullet/ExampleApplication.h:181: undefined reference to `btAxisSweep3::btAxisSweep3(btVector3 const&, btVector3 const&, unsigned short, btOverlappingPairCache*)'
/home/silwol/esd_sem01/pro/RoboSim3D/snippets/ogre-bullet/ExampleApplication.h:182: undefined reference to `btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(btStackAlloc*, btPoolAllocator*, btPoolAllocator*)'
/home/silwol/esd_sem01/pro/RoboSim3D/snippets/ogre-bullet/ExampleApplication.h:183: undefined reference to `btCollisionDispatcher::btCollisionDispatcher(btCollisionConfiguration*)'
/home/silwol/esd_sem01/pro/RoboSim3D/snippets/ogre-bullet/ExampleApplication.h:184: undefined reference to `btSequentialImpulseConstraintSolver::btSequentialImpulseConstraintSolver()'
/home/silwol/esd_sem01/pro/RoboSim3D/snippets/ogre-bullet/ExampleApplication.h:185: undefined reference to `btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btDispatcher*, btBroadphaseInterface*, btConstraintSolver*, btCollisionConfiguration*)'
collect2: ld returned 1 exit status
make: *** [trial] Error 1
pkg-config works and seems to print the correct paths:
silwol@silwol-laptop:~$ pkg-config bullet --cflags
-I/usr/local/include/bullet
silwol@silwol-laptop:~$ pkg-config bullet --libs
-L/usr/local/lib -lbulletdynamics -lbulletcollision -lbulletmath
When I look into my /usr/local/lib directory, there are libbullet*.a files, but no libbullet*.so files. What am I doing wrong?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Problem linking against installed bullet lib on Ubuntu

Post by Erwin Coumans »

When I look into my /usr/local/lib directory, there are libbullet*.a files, but no libbullet*.so files. What am I doing wrong?
Bullet only produces static libraries, so you only need the .a files.

Which build system did you use to 'install' Bullet? cmake, jam or other?

It seems they are not included in the project, anyone with Ubuntu / pkg-config experience can help?
Thanks,
Erwin
Hanz
Posts: 14
Joined: Fri Jun 01, 2007 5:36 am

Re: Problem linking against installed bullet lib on Ubuntu

Post by Hanz »

It seems they are not included in the project, anyone with Ubuntu / pkg-config experience can help?
Thanks,
Seems Ubuntu(Gutsy Gibbon), pkg-config and bullet are irrelative.
I just built the ConcavePhysicsDemo without any problem.

1. Copy source for the demo to a new directory.

2. Copy the necessary OpenGL directory to the above directory.

3. Write a very simple makefile:

Code: Select all


abc@abc-Ubuntu:~/Test/Bullet$ cat Makefile 
all: 
        g++ -I./OpenGL/ *.cpp ./OpenGL/*.cpp -o test `pkg-config bullet --cflags --libs` -lglut

clean:
        rm -rf *.o test 

4. Then build. It compiles just fine.

Code: Select all


abc@abc-Ubuntu:~/Test/Bullet$ make 
g++ -I./OpenGL/ *.cpp ./OpenGL/*.cpp -o test `pkg-config bullet --cflags --libs` -lglut
In file included from /usr/local/include/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.h:27,
                 from /usr/local/include/bullet/btBulletCollisionCommon.h:52,
                 from /usr/local/include/bullet/btBulletDynamicsCommon.h:20,
                 from ConcavePhysicsDemo.cpp:16:
/usr/local/include/bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCallback.h:37:37: warning: no newline at end of file
./OpenGL/DemoApplication.cpp: In member function 'void DemoApplication::showProfileInfo(float&, float&, float)':
./OpenGL/DemoApplication.cpp:810: warning: passing 'float' for argument 1 to 'void DemoApplication::displayProfileString(int, int, char*)'
./OpenGL/DemoApplication.cpp:810: warning: passing 'float' for argument 2 to 'void DemoApplication::displayProfileString(int, int, char*)'
./OpenGL/DemoApplication.cpp:813: warning: passing 'float' for argument 1 to 'void DemoApplication::displayProfileString(int, int, char*)'
./OpenGL/DemoApplication.cpp:813: warning: passing 'float' for argument 2 to 'void DemoApplication::displayProfileString(int, int, char*)'
./OpenGL/DemoApplication.cpp:830: warning: passing 'float' for argument 1 to 'void DemoApplication::displayProfileString(int, int, char*)'
./OpenGL/DemoApplication.cpp:830: warning: passing 'float' for argument 2 to 'void DemoApplication::displayProfileString(int, int, char*)'
./OpenGL/DemoApplication.cpp:839: warning: passing 'float' for argument 1 to 'void DemoApplication::displayProfileString(int, int, char*)'
./OpenGL/DemoApplication.cpp:839: warning: passing 'float' for argument 2 to 'void DemoApplication::displayProfileString(int, int, char*)'
./OpenGL/DemoApplication.cpp:845: warning: passing 'float' for argument 1 to 'void DemoApplication::displayProfileString(int, int, char*)'
./OpenGL/DemoApplication.cpp:845: warning: passing 'float' for argument 2 to 'void DemoApplication::displayProfileString(int, int, char*)'
abc@abc-Ubuntu:~/Test/Bullet$ 

Check your Makefile please.
silwol
Posts: 4
Joined: Wed Dec 05, 2007 6:47 pm

Re: Problem linking against installed bullet lib on Ubuntu

Post by silwol »

Erwin Coumans wrote: Bullet only produces static libraries, so you only need the .a files.

Which build system did you use to 'install' Bullet? cmake, jam or other?

It seems they are not included in the project, anyone with Ubuntu / pkg-config experience can help?
Thanks,
Erwin
I installed them using jam. It also seemed to work fine. I am simply not sure if I can link against .a files the same way I do against .so files.
silwol
Posts: 4
Joined: Wed Dec 05, 2007 6:47 pm

Re: Problem linking against installed bullet lib on Ubuntu

Post by silwol »

Hanz wrote:
It seems they are not included in the project, anyone with Ubuntu / pkg-config experience can help?
Thanks,
Seems Ubuntu(Gutsy Gibbon), pkg-config and bullet are irrelative.
I just built the ConcavePhysicsDemo without any problem.

1. Copy source for the demo to a new directory.

2. Copy the necessary OpenGL directory to the above directory.

3. Write a very simple makefile:

Code: Select all


abc@abc-Ubuntu:~/Test/Bullet$ cat Makefile 
all: 
        g++ -I./OpenGL/ *.cpp ./OpenGL/*.cpp -o test `pkg-config bullet --cflags --libs` -lglut

clean:
        rm -rf *.o test 

4. Then build. It compiles just fine.

[/code]

Check your Makefile please.
Hmmm, the only real difference I can find between your Makefile and my Makefile is that you compile the whole project with one command, and I compile the object files first and link them afterwards. You can see from my output that the pkg-config command is properly executed. Anyway, compiling everything with one command is no option for me, because in a rather large project (which this will become) a compile caused by a simple change in only one file takes very long (maybe even up to minutes) and you just can't develop anything in an efficient way with that handicap.
Hanz
Posts: 14
Joined: Fri Jun 01, 2007 5:36 am

Re: Problem linking against installed bullet lib on Ubuntu

Post by Hanz »

silwol wrote: Hmmm, the only real difference I can find between your Makefile and my Makefile is that you compile the whole project with one command, and I compile the object files first and link them afterwards.
No, please check your link option's position in your build rules. The following output is strange.
silwol wrote: cc `pkg-config OGRE --libs` `pkg-config OIS --libs` `pkg-config bullet --libs` trial.o -o trial
Maybe you should use LIBS to specify the library option?
silwol wrote: ... , because in a rather large project (which this will become) a compile caused by a simple change in only one file takes very long (maybe even up to minutes) ...
Then it is rather a small project in my mind. :wink:

HTH
silwol
Posts: 4
Joined: Wed Dec 05, 2007 6:47 pm

Re: Problem linking against installed bullet lib on Ubuntu

Post by silwol »

Hanz wrote:No, please check your link option's position in your build rules. The following output is strange.
silwol wrote:cc `pkg-config OGRE --libs` `pkg-config OIS --libs` `pkg-config bullet --libs` trial.o -o trial
This was actually only the linker output. I accidentially posted the output of a second run without running the clean target before. The output usually is as follows:

Code: Select all

g++ -Wall  `pkg-config OGRE --cflags` `pkg-config OIS --cflags` `pkg-config bullet --cflags` -g   -c -o trial.o trial.cpp
cc  `pkg-config OGRE --libs` `pkg-config OIS --libs` `pkg-config bullet --libs`   trial.o   -o trial
In my opinion the flags seem to be placed on the right positions.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Problem linking against installed bullet lib on Ubuntu

Post by Erwin Coumans »

Can you try some Ubuntu user mailing list to get help?

Another way is to manually create the Bullet library using your build system, instead of jam.

You simply recursively add all files in the Bullet/src folder, and add Bullet/src as include path.

Hope this helps,
Erwin
kuxv
Posts: 9
Joined: Sun Mar 30, 2008 2:10 pm

Re: Problem linking against installed bullet lib on Ubuntu

Post by kuxv »

If anybody interested I've found solution. You have to put objects files BEFORE libs when linking, i.e.

Code: Select all

g++ obj1.o obj2.o `pkg-config --libs bullet` -o target
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: Problem linking against installed bullet lib on Ubuntu

Post by sparkprime »

Yeah you have to put the .o and .a files in reverse order of dependency (i.e. the top level stuff first) because any symbols in a .a file that are not required at that stage (going left to right along the command line) get forgotten about, even if they are needed further along the command line. This is to allow linking only what is needed, to keep binary sizes small. I think you can also use it to control what symbols get used when you have two .a files exporting the same symbol.