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?
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.