【发布时间】:2019-08-18 15:59:02
【问题描述】:
我正在尝试设置一个环境来开发 Ogre3D 应用程序。我已经手动将 Ogre 编译到文件夹 /opt/Ogre3D/ogre-1.11.5/build 中,并在 CLion 中创建了一个包含以下内容的 CMake 项目:
cmake_minimum_required(VERSION 3.13)
project(sample)
set(CMAKE_CXX_STANDARD 14)
set(OGRE_DIR /opt/Ogre3D/ogre-1.11.5/build/sdk/cmake)
# specify which version and components you need
find_package(OGRE 1.11 REQUIRED COMPONENTS Bites RTShaderSystem)
# copy resource.cfg next to our binaries where OGRE looks for it
file(COPY ${OGRE_CONFIG_DIR}/resources.cfg DESTINATION ${CMAKE_BINARY_DIR})
add_executable(sample main.cpp)
target_link_libraries(sample ${OGRE_LIBRARIES})
当我尝试运行它时,编译是可以的,但是它不能执行它:
/Users/diego/CLionProjects/ogre/sample/cmake-build-debug/sample
dyld: Library not loaded: @executable_path/../Frameworks/OgreBites.framework/Versions/1.11.5/OgreBites
Referenced from: /Users/diego/CLionProjects/ogre/sample/cmake-build-debug/sample
Reason: image not found
Process finished with exit code 6
我查看了otool -l /opt/Ogre3D/ogre-1.11.5/build/lib/macosx/OgreBites.framework/Versions/1.11.5/OgreBites,有一个名为@executable_path/../Frameworks/OgreBites.framework/Versions/1.11.5/OgreBites 的命令LC_ID_DYLIB,它与运行时错误中给出的路径相匹配。但是我不知道现在该采取哪一步,因为我对 macOS 上的本机库解析经验很少。
更新:
执行命令install_name_tool 会使链接器找到库,但随后它会因下一个库而失败。我想/希望 CMake 中有一个选项可以将其传递给编译器,因此在 Ogre 编译期间创建的二进制文件不使用 @execute_path 指令?
【问题讨论】:
-
你能解析@executable_path/../Frameworks并检查dylib是否在里面吗?
-
@executable_path 解析为执行编译程序的文件夹,在我的例子中是
/Users/diego/CLionProjects/ogre/sample/cmake-build-debug。但是,该库位于/opt/Ogre3D/ogre-1.11.5/build/lib/macosx/OgreBites.framework/Versions/1.11.5中,这是一个不同的文件夹。使用install_name_tool -change @executable_path/../Frameworks/OgreBites.framework/Versions/1.11.5/OgreBites /opt/Ogre3D/ogre-1.11.5/build/lib/macosx/OgreBites.framework/Versions/1.11.5/OgreBites sample解决了这个问题,但是下一个库会失败。