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.
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/
.
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)