Mac OS X上的MathGL和FLTK cmake:找不到符号

时间:2014-10-21 01:57:56

标签: macos cmake fltk mathgl

我无法让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等,当这些已经通过BUNDLE_MODE中的add_executable var进行链接时。我怀疑这个特定的FindFLTK2.cmake在OS X上没有经过适当的测试,我不太确定如何修复它。

有人可以建议一个简单的解决方法吗?

1 个答案:

答案 0 :(得分:0)

发现问题。似乎FindMathGL.cmakeFindMathGL2.cmake中的说明都不正确。这是更正的cmake指令集。这也适用于Qt,而不仅仅是FLTK。

find_package(MathGL2 REQUIRED COMPONENTS FLTK) # or Qt instead of FLTK
include_directories(${MATHGL2_INCLUDE_DIRS})

add_executable(filter ${BUNDLE_MODE} src/filter.cpp) # leave out BUNDLE_MODE if not on Darwin

target_link_libraries(
  filter
  ${MATHGL2_LIBRARIES}
  ${OPENGL_LIBRARIES}
)

更容易。