【发布时间】:2015-12-04 06:49:04
【问题描述】:
我有一个(相对)大的 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")
【问题讨论】:
-
你在使用 Xcode 吗?如果是这样,这里是什么样子:Xcode > 项目 > 目标 > 构建阶段 > 链接库...此外,Xcode > 目标 > 构建设置...这里有各种库链接
-
我正在链接在我的项目中编译的库,这些库在安装后位于 ${CMAKE_INSTALL_PREFIX}/lib/${MACHTYPE} 文件夹中
-
otool -D <library name>.dylib在其安装位置的输出是什么?