【发布时间】:2014-10-21 01:57:56
【问题描述】:
我无法让 cmake 找到并链接 MathGL 和 FLTK 的必要库。
Linking CXX executable filter.app/Contents/MacOS/filter
Undefined symbols for architecture x86_64:
"_mgl_create_graph_fltk", referenced from:
_main in filter.cpp.o
"_mgl_fltk_thr", referenced from:
_main in filter.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我正在使用默认的 FLTK finder cmake 脚本,它在 OS X 上随 brewed CMake 3.0.2 一起提供。
这是我CMakeLists.txt的相关部分:
find_package(MathGL 2.2 REQUIRED)
include_directories(${MATHGL2_INCLUDE_DIRS})
find_package(FLTK REQUIRED)
include_directories(${FLTK_INCLUDE_DIR})
#link_directories(${FLTK_LIBRARIES}) # tried it with and without this line
add_executable(filter ${BUNDLE_MODE} src/filter.cpp)
target_link_libraries(
filter
${MATHGL2_LIBRARIES}
${FLTK_LIBRARIES}
${OPENGL_LIBRARIES}
)
如果我取消注释 link_directories 行,我会收到一个额外的错误:
CMake Warning (dev) at CMakeLists.txt:73 (link_directories):
This command specifies the relative path
-framework Carbon -framework Cocoa -framework ApplicationServices -lz
as a link directory.
Policy CMP0015 is not set: link_directories() treats paths relative to the
source dir. Run "cmake --help-policy CMP0015" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
似乎它正在尝试执行-L-framework Carbon 等,而这些已经通过add_executable 中的BUNDLE_MODE var 链接。我怀疑这个特定的FindFLTK2.cmake 没有在 OS X 上正确测试,并且不太确定如何修复它。
谁能提出一个简单的解决办法?
【问题讨论】:
-
不熟悉cmake,但看起来问题出在mathGL上。您是否手动检查过 mathGL 库是否在您认为的位置?作为蛮力检查,您是否尝试过使用 g++ 和
fltk-config从命令行编译并从那里链接到 MathGL?