0

我无法让 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_MODEvar in链接时,它似乎正在尝试做等add_executable。我怀疑这个特殊FindFLTK2.cmake的东西没有在 OS X 上正确测试,并且不太确定如何修复它。

谁能建议一个简单的修复?

4

1 回答 1

0

发现了问题。似乎两者中的说明FindMathGL.cmake都不FindMathGL2.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}
)

容易得多。

于 2014-10-26T23:27:14.037 回答