【问题标题】:How to add the Bullet physics library to a c++ program如何将 Bullet 物理库添加到 C++ 程序
【发布时间】:2019-04-02 23:32:36
【问题描述】:

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

#include <btBulletDynamicsCommon.h>

int main(){
}

我注意到头文件位于 build_cmake/src 目录中,所以我将它包含在 -I 中,这可行,但后来我遇到了链接错误,所以我找到了 .so 文件并使用 -L 选项链接它们和一些消除链接错误的球,但我仍然有警告。以下命令给了我一个可执行文件:

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


    【解决方案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
    

    【讨论】:

      【解决方案2】:

      看起来不错,但是 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 上找到

      【讨论】:

      • 还是出现同样的错误,感谢指正!
      • 能不能对编译好的程序运行ldd命令。例如ldd a.out
      • 我已经在原帖中添加了输出!
      • 所以看起来错误并不完全相同,我正在努力将所有 9 个库添加到我的 LD_LIBRARY_PATH
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多