我有一个(相对)大项目C ++,可以在ubuntu上编译和运行(使用cmake / catkin)。 它在mac os上编译很好,但在尝试启动可执行文件时,我收到错误消息:
dyld: Library not loaded: <name of library>.dylib
Referenced from:
<path to executable>/<executable>
Reason: image not found
运行命令时:
otool -l <executable> | grep LC_RPATH -A2
我得到了输出:
cmd LC_RPATH
cmdsize 64
path <correct absolute path to folder containing library> (offset 12)
cmd LC_RPATH
cmdsize 24
path /sw/lib (offset 12)
cmd LC_RPATH
cmdsize 32
path /usr/X11/lib (offset 12)
cmd LC_RPATH
cmdsize 32
path /opt/local/lib (offset 12)
cmd LC_RPATH
cmdsize 32
path /opt/X11/lib (offset 12)
我很不清楚为什么找不到图书馆。 运行:
otool -L <executable>
打印:
<executable name>:
<library name>.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
/opt/X11/lib/libglut.3.dylib (compatibility version 13.0.0, current version 13.0.0)
/opt/X11/lib/libGL.1.dylib (compatibility version 1.2.0, current version 1.2.0)
/opt/X11/lib/libGLU.1.dylib (compatibility version 1.3.0, current version 1.3.0)
/opt/X11/lib/libX11.6.dylib (compatibility version 10.0.0, current version 10.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
似乎证实它没有得到正确的道路。
我缺少什么?
PS:
不确定它是否相关,这里是我使用的cmake命令: (来自here)
# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/${MACHTYPE}")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib/${MACHTYPE}" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/${MACHTYPE}")
ENDIF("${isSystemDir}" STREQUAL "-1")
答案 0 :(得分:1)
答案来自here
的评论我需要使用@rpath
实际上Mac OS X确实有rpath的概念。 10.4之前 只有@executable_path指向了该位置 可执行二进制文件(与其加载的任何dylib相对)。 在10.4中引入了@loader_path,允许加载dylib 基于其位置的依赖关系(而不是关于它的位置) 可执行文件 - 谁知道使用该库的内容。
随着10.5苹果推出@rpath,它被加载到装载中 二进制 - 可执行文件或库。所以不要看: 您可能会看到@loader_path /../../ Library / Frameworks / blah.dylib @ rpath的/库/框架/ blah.dylib
这意味着如果将rpath设置为。和/它会看 ./Library/Frameworks/blah.dylib然后 /Library/Frameworks/blah.dylib适用于任何图书馆。