0

I'm having trouble getting cmake to find and link the necessary libraries for MathGL and 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)

I'm using the default FLTK finder cmake script, which comes with brewed CMake 3.0.2 on OS X.

Here are the relevant portions of my 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}
)

If I uncomment the link_directories line, I get an additional error:

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.

It seems like it's trying to do -L-framework Carbon, etc., when these are already being linked via the BUNDLE_MODE var in add_executable. I suspect this particular FindFLTK2.cmake was not properly tested on OS X, and am not quite sure how to fix it.

Can anyone suggest a simple fix?

Translunar
  • 3,739
  • 33
  • 55
  • Not familiar with cmake, but it looks like the trouble is linking to mathGL. Have you checked, manually, that the mathGL libs are where you think they are? As a brute force check, have you tried compiling from the command line with g++ and `fltk-config` and linking to MathGL from there? – user3353819 Oct 23 '14 at 10:13

1 Answers1

0

Found the problem. It seems that the instructions in both FindMathGL.cmake and FindMathGL2.cmake were incorrect. Here is the corrected cmake instruction set. This also works for Qt, not just 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}
)

Much easier.

Translunar
  • 3,739
  • 33
  • 55