undefined reference to btAlignedAllocInternal(unsigned long, int)

Post Reply
mrBrown
Posts: 2
Joined: Thu Aug 15, 2019 4:09 pm

undefined reference to btAlignedAllocInternal(unsigned long, int)

Post by mrBrown »

Hi,

I've recently switched from Visual Studio on Windows to Ubuntu. I'm working on a project that used the LinearMath part of Bullet.
When I try to compile my program I get an undefined reference to "btAlignedAllocInternal(unsigned long, int)" error.

On windows I only reference to the LinearMath library but I figured out that the btAlignedAllocInternal may actually be defined in Bullet3Common. So I link to both of them.

Probably something I'm overlooking but I could use some help in finding out what.

My "program" looks as follows:

Code: Select all

#include <iostream>
#include "btVector3.h"

int main() {

    std::cout << "Hello world...\n";
    btVector3* test = new btVector3(1,2,3);
    std::cout << "...Hello to you " << test[1] << "\n";
    
    return 0;
}
and I'm trying to get it to run using:

Code: Select all

g++ \
   -O3 \
   -Wall \
   -std=c++14 \
   -fPIC \
   -DBT_USE_DOUBLE_PRECISION \
   -Ibullet3/src/LinearMath \
   -Lbullet3/build_cmake/src/Bullet3Common \
   -lBullet3Common \
   -Lbullet3/build_cmake/src/LinearMath \
   -lLinearMath \
   main.cpp
echo "Build completed; running program"
./a.out
The exact error is:

Code: Select all

/tmp/ccDDKxGV.o: In function `main':
main.cpp:(.text.startup+0x27): undefined reference to `btAlignedAllocInternal(unsigned long, int)'
collect2: error: ld returned 1 exit status
I did run ./build_cmake_pybullet_double.sh and the .so files are present.
mrBrown
Posts: 2
Joined: Thu Aug 15, 2019 4:09 pm

Re: undefined reference to btAlignedAllocInternal(unsigned long, int)

Post by mrBrown »

Ok, solved it.

The actual order of arguments is important. I first listed linearMath and then main.cpp. This should be the other way around since the unresolved symbols in main.cpp can be found in linearMath.

Then, for running, the system needs to be able to find the libLinearMath.so.2.88 file. I solved that by adding the path to the file to /etc/ld.so.conf and running ldconfig.

So the correct command to build is:

Code: Select all

g++ \
   -O3 \
   -Wall \
   -std=c++14 \
   -Lbullet3/build_cmake/src/LinearMath \
   -fPIC \
   -DBT_USE_DOUBLE_PRECISION \
   -Ibullet3/src/LinearMath \
   main.cpp \
   -lLinearMath
Post Reply