如何将Bullet物理库添加到c ++程序中

问题描述 投票:0回答:2

我已经从https://github.com/bulletphysics/bullet3编译了库并测试了一些示例,但我似乎无法编译这个简单的程序。

#include <btBulletDynamicsCommon.h>

int main(){
}

我注意到头文件位于build_cmake / src目录中,因此我将它包含在-I中,但是我有链接错误,所以我找到了.so文件,并将它们与-L选项和一些globs相关联这删除了链接错误,但我仍然有警告。以下命令给了我一个可执行文件:

g++ -Wall main.cpp -I bullet3/src/ -L bullet3/build_cmake/src/*/*.so

但有以下警告:

In file included from bullet3/src/btBulletDynamicsCommon.h:38:0,
                 from main.cpp:3:
bullet3/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h: In constructor ‘btSISolverSingleIterationData::btSISolverSingleIterationData(btAlignedObjectArray<btSolverBody>&, btConstraintArray&, btConstraintArray&, btConstraintArray&, btConstraintArray&, btAlignedObjectArray<int>&, btAlignedObjectArray<int>&, btAlignedObjectArray<int>&, btAlignedObjectArray<btTypedConstraint::btConstraintInfo1>&, btScalar (*&)(btSolverBody&, btSolverBody&, const btSolverConstraint&), btScalar (*&)(btSolverBody&, btSolverBody&, const btSolverConstraint&), btScalar (*&)(btSolverBody&, btSolverBody&, const btSolverConstraint&), btAlignedObjectArray<int>&, long unsigned int&, int&, int&)’:
bullet3/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h:49:29: warning: ‘btSISolverSingleIterationData::m_kinematicBodyUniqueIdToSolverBodyTable’ will be initialized after [-Wreorder]
  btAlignedObjectArray<int>& m_kinematicBodyUniqueIdToSolverBodyTable;
                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bullet3/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h:44:17: warning:   ‘long unsigned int& btSISolverSingleIterationData::m_seed’ [-Wreorder]
  unsigned long& m_seed;
                 ^~~~~~
bullet3/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h:57:2: warning:   when initialized here [-Wreorder]
  btSISolverSingleIterationData(btAlignedObjectArray<btSolverBody>& tmpSolverBodyPool,
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

当我运行可执行文件时出现错误:

./a.out: error while loading shared libraries: libBullet3Dynamics.so.2.88: cannot open shared object file: No such file or directory

我试图将文件添加到我的LD路径:

export LD_LIBRARY_PATH=/home/sam/code/bullet/bullet3/build_cmake/src/Bullet3Common/libBullet3Common.so.2.88:$LD_LIBRARY_PATH

但得到了同样的错误。

看起来我过于复杂了,但我似乎无法在网上找到如何编译这样的程序的任何例子......

编辑:

我在Debian Linux上。

编辑2:

输出ldd:

linux-vdso.so.1 (0x00007ffdecb04000)
libBullet3Common.so.2.88 => /home/sam/code/bullet/bullet3/build_cmake/src/Bullet3Common/libBullet3Common.so.2.88 (0x00007fd0246e7000)
libBullet3Dynamics.so.2.88 => not found
libBullet3Geometry.so.2.88 => not found
libBullet3OpenCL_clew.so.2.88 => not found
libBulletCollision.so.2.88 => not found
libBulletDynamics.so.2.88 => not found
libBulletInverseDynamics.so.2.88 => not found
libBulletSoftBody.so.2.88 => not found
libLinearMath.so.2.88 => not found
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fd024365000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd024061000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fd023e4a000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd023aab000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd024aee000)
c++ compilation bullet
2个回答
1
投票

看起来不错,但是LD_LIBRARY_PATH应该指向目录,而不是库文件本身。

因此,请尝试将LD_LIBRARY_PATH命令更改为:

export LD_LIBRARY_PATH=/home/sam/code/bullet/bullet3/build_cmake/src/Bullet3Common/:$LD_LIBRARY_PATH

编辑后:

因此,查看ldd的输出,它表明它找不到它需要的几个库。

确保在LD_LIBRARY_PATH上都可以找到这些内容


1
投票

感谢ddd4帮助我完成导出工作。这些是我必须用来为将来遇到此问题的人设置正确路径的命令:

export LD_LIBRARY_PATH=/home/sam/code/bullet/bullet3/build_cmake/src/Bullet3Common:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/sam/code/bullet/bullet3/build_cmake/src/Bullet3Dynamics:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/sam/code/bullet/bullet3/build_cmake/src/Bullet3Geometry:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/sam/code/bullet/bullet3/build_cmake/src/Bullet3OpenCL:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/sam/code/bullet/bullet3/build_cmake/src/Bullet3OpenCL_clew:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/sam/code/bullet/bullet3/build_cmake/src/BulletCollision:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/sam/code/bullet/bullet3/build_cmake/src/BulletDynamics:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/sam/code/bullet/bullet3/build_cmake/src/BulletInverseDynamics:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/sam/code/bullet/bullet3/build_cmake/src/BulletSoftBody:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/home/sam/code/bullet/bullet3/build_cmake/src/LinearMath:$LD_LIBRARY_PATH
© www.soinside.com 2019 - 2024. All rights reserved.