【问题标题】:dyld not loading Ogre librarydyld 没有加载 Ogre 库
【发布时间】: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 解决了这个问题,但是下一个库会失败。

标签: c++ macos clion ogre dyld


【解决方案1】:

我在macos中使用clion构建ogre时遇到了同样的问题。

我发现目录 cmake-build-debug/bin/SampleBrowser.app/Contents/Frameworks 中的符号链接无效

我猜这些符号链接应该指向 这些框架在 cmake-build-debug/lib/macosx 中。所以我修改了执行ln的文件来创建这些符号链接。

在文件 Samples/Browser/CMakeLists.txt 中,更改

set(OGRE_OSX_BUILD_CONFIGURATION "${CMAKE_OSX_SYSROOT}/$(CONFIGURATION)")

进入

set(OGRE_OSX_BUILD_CONFIGURATION "macosx")

然后清理并重建,然后问题就会消失。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-05
    • 2015-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多