macports,cmake / make和'dyld:库没有加载'

时间:2016-02-10 19:34:53

标签: cmake makefile macports dylib linkage

我最近使用macports升级了我在我的项目(glfw-devel)中使用的库,现在我的可执行文件与lib/libglfw.3.dylib而不是opt/local/lib/libglfw.3.dylib动态链接,这是lib的实际位置所以我收到dyld: Library not loaded错误。

我知道如何使用install-names或使用简单副本解决此问题。然而,我无法理解的是,为什么在简单升级后会突然发生这种情况。我没有更改CMakeLists.txt中的任何内容(下面最相关的部分),我使用的所有其他库都有正确的路径。请注意,文件中没有我引用lib/的地方。

这可能是与macports相关的问题吗?如何确保我的未来二进制文件将使用正确的路径进行编译?

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)

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。我花了好几个小时来搞清楚。 原来,这个问题是glfw版本所关注的。 glfw 3.1版还可以。试试吧。

或者该错误已发布在Macports错误列表中:glfw @3.2: install_name is not set properly