我是cmake的新手,所以我不知道自己做错了什么。我已经编写了一个自定义的Find * .cmake文件来查找特定的程序包(与Basler GigE / Usb相机配合使用的Pylon SDK)。似乎找到了编译和链接成功所需的所有内容,但是当我尝试运行程序时,出现以下错误:
dyld: Library not loaded: @rpath
Referenced from: <long/path/to/my/project/bin/dir/BaslerImgAcq>
Reason: image not found
Abort trap: 6
运行otool -L ./BaslerImgAcq
时,得到以下输出:
./BaslerImgAcq:
@rpath/libopencv_highgui.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/pylon.framework/Versions/A/Libraries/libGCBase_gcc_v3_0_Basler_pylon_v5_0.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/pylon.framework/Versions/A/Libraries/libGenApi_gcc_v3_0_Basler_pylon_v5_0.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/pylon.framework/Versions/A/Libraries/libLog_gcc_v3_0_Basler_pylon_v5_0.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/pylon.framework/Versions/A/Libraries/libMathParser_gcc_v3_0_Basler_pylon_v5_0.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/pylon.framework/Versions/A/Libraries/libNodeMapData_gcc_v3_0_Basler_pylon_v5_0.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/pylon.framework/Versions/A/Libraries/libXmlParser_gcc_v3_0_Basler_pylon_v5_0.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/pylon.framework/Versions/A/Libraries/libgxapi-5.0.5.dylib (compatibility version 5.0.0, current version 5.0.5)
@rpath/pylon.framework/Versions/A/Libraries/liblog4cpp_gcc_v3_0_Basler_pylon_v5_0.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/pylon.framework/Versions/A/Libraries/libpylonbase-5.0.5.dylib (compatibility version 5.0.0, current version 5.0.5)
@rpath/pylon.framework/Versions/A/Libraries/libpylonutility-5.0.5.dylib (compatibility version 5.0.0, current version 5.0.5)
@rpath/pylon.framework/Versions/A/Libraries/libuxapi-5.0.5.dylib (compatibility version 5.0.0, current version 5.0.5)
@rpath (compatibility version 2.0.0, current version 2.0.0)
@rpath/libopencv_imgcodecs.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/libopencv_imgproc.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
@rpath/libopencv_core.3.2.dylib (compatibility version 3.2.0, current version 3.2.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4)
可以看出其中有一个@rpath条目为空,尽管我可能是错的,但我认为这是导致问题的原因。
在我的CMakeLists.txt文件中,我使用以下几行找到了Pylon库:
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
find_package(Pylon REQUIRED)
,然后在我项目的cmake / modules文件夹中,相关代码为:
find_path(Pylon_FRAMEWORK_DIR NAMES pylon
HINTS /Library/Frameworks/pylon.framework)
if(Pylon_FRAMEWORK_DIR)
# Pylon has been found
set(Pylon_FOUND TRUE)
# Include directory:
find_path(Pylon_INCLUDE_DIRS NAMES PylonIncludes.h
HINTS ${Pylon_FRAMEWORK_DIR}/Headers)
if (Pylon_INCLUDE_DIRS)
message(STATUS "Pylon_INCLUDE_DIRS = ${Pylon_INCLUDE_DIRS}")
endif(Pylon_INCLUDE_DIRS)
# Library directory:
find_path(Pylon_LIBDIR NAMES libpylonbase.dylib
HINTS ${Pylon_FRAMEWORK_DIR}/Libraries)
if (Pylon_LIBDIR)
message(STATUS "Pylon_LIBDIR = ${Pylon_LIBDIR}")
endif(Pylon_LIBDIR)
# Clear Pylon_LIBRARIES variable (just in case not empty):
unset(Pylon_LIBRARIES CACHE)
# Find all library files in Pylon_LIBDIR:
file(GLOB Pylon_LIBS ${Pylon_LIBDIR}/ *.dylib)
foreach(Pylon_LIB ${Pylon_LIBS})
get_filename_component(Pylon_LIB ${Pylon_LIB} NAME)
find_library(Pylon_LIBRARY NAMES ${Pylon_LIB} HINTS ${Pylon_LIBDIR})
if(Pylon_LIBRARY)
list(APPEND Pylon_LIBRARIES ${Pylon_LIB})
add_library(${Pylon_LIB} SHARED IMPORTED)
set_property(TARGET ${Pylon_LIB} PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Pylon_INCLUDE_DIRS})
set_property(TARGET ${Pylon_LIB} PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${Pylon_INCLUDE_DIRS})
set_property(TARGET ${Pylon_LIB} PROPERTY IMPORTED_LOCATION ${Pylon_LIBRARY})
else(Pylon_LIBRARY)
message(STATUS "Could not find ${Pylon_LIB}")
endif(Pylon_LIBRARY)
unset(Pylon_LIBRARY CACHE)
endforeach(Pylon_LIB ${Pylon_LIBS})
set(HAVE_Pylon TRUE)
else(Pylon_FRAMEWORK_DIR)
set(Pylon_FOUND FALSE)
endif(Pylon_FRAMEWORK_DIR)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Pylon
FOUND_VAR Pylon_FOUND
REQUIRED_VARS Pylon_LIBRARIES Pylon_INCLUDE_DIRS
VERSION_VAR Pylon_VERSION)
以更好的方式包括OSX框架(我敢肯定必须有一个更简单的方式),将不胜感激,但是无论如何,我也想知道为什么这段代码会产生一个空的@rpath。