【发布时间】:2021-01-14 15:17:20
【问题描述】:
我已经在Windows上使用cmake构建了bullet3-3.08(命令已经从bullet3-3.08目录中创建的build文件夹执行):
cmake -G "Visual Studio 15 2017" -A x64 -D "CMAKE_INSTALL_PREFIX:PATH=C:/MyLibs/bullet3-3.08" -D "USE_MSVC_RUNTIME_LIBRARY_DLL=ON" -D "INSTALL_LIBS=ON" ..
cmake --build . --config Release --parallel 8 --target install
我有一个使用 MD/MDd 运行时库的应用程序,因此我使用以下选项构建了 Bullet:USE_MSVC_RUNTIME_LIBRARY_DLL=ON。 Bullet 默认构建为静态库。我使用 Visual Studio 2017 并使用 cmake 构建我的应用程序。当我链接到 Bullet 时,我收到许多链接器错误(LNK2019、LNK2001),例如:
error LNK2019: unresolved external symbol "public: __cdecl btCollisionDispatcher::btCollisionDispatcher(class btCollisionConfiguration *)" (??0btCollisionDispatcher@@QEAA@PEAVbtCollisionConfiguration@@@Z) referenced in function main
error LNK2001: unresolved external symbol "public: virtual void __cdecl btCollisionShape::getBoundingSphere(class btVector3 &,float &)const " (?getBoundingSphere@btCollisionShape@@UEBAXAEAVbtVector3@@AEAM@Z)
我在 CMakeLists.txt 中使用直接库路径:
target_link_libraries(${executableName} "C:/MyLibs/bullet3-3.08/lib/Bullet3Collision.lib"
"C:/MyLibs/bullet3-3.08/lib/Bullet3Dynamics.lib"
"C:/MyLibs/bullet3-3.08/lib/LinearMath.lib")
这里是 CMakeSettings.json:
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [
"msvc_x64_x64"
],
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [
"msvc_x64_x64"
],
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-v",
"ctestCommandArgs": ""
}
]
}
怎么了?
【问题讨论】:
标签: cmake visual-studio-2017 static-libraries static-linking bullet