macports,cmake / make和'dyld:Library not loaded' [英] macports, cmake/make and 'dyld: Library not loaded'
问题描述
我最近升级了一个我在我的项目(glfw-devel)中使用macports的库,现在我的可执行文件动态链接到 lib / libglfw.3.dylib
而不是 opt / local / lib / libglfw.3.dylib
这是lib的实际位置,所以我得到一个 dyld:Library not loaded
错误。
I recently upgraded a library I use in a project of mine (glfw-devel) with macports and now my executable is dynamically link with lib/libglfw.3.dylib
instead of opt/local/lib/libglfw.3.dylib
which is the actual location of the lib so I get a dyld: Library not loaded
error.
我知道如何使用 install-names
或简单的副本来解决这个问题。然而,我不能理解的是为什么这种情况在简单升级后突然发生。我没有改变任何在我的 CMakeLists.txt
(最相关的部分是下面),我使用的所有其他库具有正确的路径。注意,在文件中没有指向 lib /
的地方。
I know how to fix this with install-names
or with a simple copy. What I cannot understand, however, is why this happens suddenly after a simple upgrade. I haven't changed anything in my CMakeLists.txt
(the most relevant part is below) and all the other libraries I use have correct paths. Note that there is no place in the file where I refer to lib/
.
它可以是一个macports相关问题?
Could it be a macports related issue? How can I make sure that my future binaries will be compiled with the proper paths?
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++14 -stdlib=libc++ -DBOOST_LOG_USE_NATIVE_SYSLOG")
set (SOURCES src/helper.cpp
src/capture.cpp
src/imageBuffer.cpp
src/projection.cpp
)
set (APP_SOURCES src/main.cpp )
set (TEST_SOURCES src/tests.cpp
lib/gmock-all.cc
lib/gtest-all.cc)
include_directories(/opt/local/include
/usr/local/include
/usr/local/include/gmock
/usr/local/include/gtest
src
)
set (DYN_LINK /opt/local/lib
/usr/local/lib)
set (STATIC_LINK static)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/Install")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Install")
find_package(Boost 1.59.0 COMPONENTS
log
log_setup
thread
date_time
filesystem
system
program_options
REQUIRED)
find_package(OpenCV 3.0 REQUIRED)
if (OpenCV_FOUND)
message( "-- OpenCV found")
endif()
find_package(OpenGL REQUIRED)
if (OpenGL_FOUND)
message( "-- OpenGL found")
endif()
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${OpenCV_INCLUDE_DIRS})
#user configuration
if(${CMAKE_LINKAGE} MATCHES Static)
message("-- STATIC LINKAGE SELECTED")
link_directories(${STATIC_LINK})
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
set(BUILD_SHARED_LIBRARIES OFF)
else()
message("-- DYNAMIC LINKAGE SELECTED")
#find libraries
link_directories(${DYN_LINK})
link_directories(${Boost_LIBRARY_DIR})
link_directories(${Boost_LIBRARY_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_ALL_DYN_LINK")
set(Boost_USE_STATIC_LIBS OFF)
endif()
if(${CMAKE_BUILD_MODE} MATCHES Release)
message("-- RELEASE MODE ON")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
else()
message("-- DEBUG MODE ON")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DDEBUG")
endif()
# core
add_library(core ${SOURCES})
target_link_libraries(core ${OpenCV_LIBS})
target_link_libraries(core ${Boost_LIBRARIES})
target_link_libraries(core ${OPENGL_LIBRARIES})
target_link_libraries(core GLEW)
target_link_libraries(core glfw)
推荐答案
它花了我几个小时才弄清楚。
原来,这个问题是glfw版本有关。 glfw版本3.1是确定。尝试。
I encountered the same problem. And It took me hours to figure it out. It turned out that this problem is glfw version concerned. glfw version 3.1 is ok. Try it.
或者该bug已发布在Macports错误列表中: glfw @ 3.2:install_name未正确设置
Or the bug had been posted in Macports buglist: glfw @3.2: install_name is not set properly
这篇关于macports,cmake / make和'dyld:Library not loaded'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!