Search code examples
c++linuxcmakeinclude-pathbullet

linking bullet include directory with cmake


I have a common problem, "include not found". While I was using the command line to set the includes and libraries directories everything was fine, Quote:

g++ src/B_engine.cc -lLinearMath -lBulletSoftBody -lBulletCollision -lBulletDynamics -I/usr/include/bullet -o a.out

but I need to make it working with cmake, there is a copy of my current cmake,

cmake_minimum_required( VERSION 2.8 )
project( a.out )
set( SOURCES src/B_engine.cc )
set( EXECUTABLE_NAME a.out )
find_package( Bullet REQUIRED )
add_executable( ${EXECUTABLE_NAME} ${SOURCES} )
add_definitions(-std=c++11)

when I do a "ccmake .", I see :

BULLET_INCLUDE_DIR /usr/include/bullet
CMAKE_BUILD_TYPE
CMAKE_INSTALL_PREFIX /usr/local

so, me (with the command line) and cmake are expecting to use /usr/include/bullet as directory. But when I do "make", I get this error :

[100%]
Scanning dependencies of target a.out
Building CXX object CMakeFiles/a.out.dir/src/B_engine.cc.o
In file included from /home/user/test/src/B_engine.cc:2:0:/home/user/test/src/B_engine.hh:5:36: fatal error: btBulletDynamicsCommon.h: No such file or directory
 #include <btBulletDynamicsCommon.h>

I do not understand why the g++ command line and cmake doesn't give the same result.


Solution

  • Maybe the find_package script for Bullet only locates the include dir but does not add it to the include list. So I'd add it explicitly:

    include_directories(${BULLET_INCLUDE_DIR})