20160614:
我有MacPorts安装的glfw。
sudo port install glfw
我已经检查过/opt/local/lib/libglfw.dylib是否存在。
这是main.cpp的顶部标题:
#include <GLFW/glfw3.h>
我的CMakeLists.txt(file1):
cmake_minimum_required (VERSION 2.8)
project (t1)
include_directories(/opt/local/include)
link_directories(/opt/local/lib)
# find_library(MYGLFWLIB NAMES glfw HINTS /opt/local/lib NO_DEFAULT_PATH)
set(GLLIBS GL glfw glew)
add_executable(t1 main.cpp)
target_link_libraries(t1 ${GLLIBS})
在没有报告错误的cmake . && make
之后,我按./t1
执行
然后出现错误:
dyld: Library not loaded: lib/libglfw.3.dylib
Referenced from: /Users/...../t1
Reason: image not found
[1] 13949 trace trap ./t1
然后我使用otool -L t1
检查t1中的lib dependens
/opt/local/lib/libGL.1.dylib (compatibility version 4.0.0, current version 4.0.0)
lib/libglfw.3.dylib (compatibility version 3.0.0, current version 3.2.0)
/opt/local/lib/libGLEW.1.13.0.dylib (compatibility version 1.13.0, current version 1.13.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
有人可以告诉我为什么glfw没有正确链接?
20160615:
修改我的CMakeLists.txt(file2)后:
cmake_minimum_required (VERSION 2.8)
project (t1)
include_directories(/opt/local/include)
link_directories(/opt/local/lib)
find_library(GL_LIB GL HINTS /opt/local/lib )
find_library(GLFW_LIB glfw HINTS /opt/local/lib)
find_library(GLEW_LIB glew HINTS /opt/local/lib)
message(${GLFW_LIB})
message(${GLEW_LIB})
message(${GL_LIB})
add_executable(t1 main.cpp)
target_link_libraries(t1 ${GL_LIB} ${GLFW_LIB} ${GLEW_LIB})
我有两个osx设备(MacMini和MacBookPro),MacPorts和Xcode以及CMake和System的版本都是一样的:
Mac osx:10.11.5 MacPorts 2.3.4 CMake:3.5.2 Xcode:7.3
两种版本的CMakeLists(上面的file1和file2)都适用于MacMini,链接器工作正常。 但当它出现在我的MacBookPro上时,glfw没有很好地连接。
其他人遇到了几乎相同的问题:
macports-cmake-make-dyld-library-not-loaded
这个问题是SYSTEM VARIABLE有关吗?
答案 0 :(得分:2)
搜索了几个小时后,我找到了原因:glfw @3.2: install_name is not set properly
答案 1 :(得分:0)
set(GLLIBS GL glfw glew)
那不是你应该如何使用CMake。使用find_library
或
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
target_link_libraries(simple ${GLFW_LIBRARIES})