[CMake] Missing 'undefined dynamic_lookup' flag
Cedric Doucet
cedric.doucet at inria.fr
Thu Mar 9 17:41:03 EST 2017
Hello,
I am trying to find a portable way of generating modules with CMake.
Here is a toy CMake script:
-------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(dlopen_example CXX)
ADD_EXECUTABLE(main main.cpp print_ref.cpp)
TARGET_LINK_LIBRARIES(main dl)
ADD_LIBRARY(module MODULE module.cpp)
-------------------------------
This script works fine with g++ on Linux Ubuntu.
However, I get an error message with clang on Mac OSX:
----------------------------
Undefined symbols for architecture x86_64:
"print_ref()", referenced from:
_module in module.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)
make[2]: *** [libmodule.so] Error 1
make[1]: *** [CMakeFiles/module.dir/all] Error 2
make: *** [all] Error 2
----------------------------
I found a solution to this problem by adding the 'undefined dynamic_lookup' flag :
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -undefined dynamic_lookup")
But, I am surprised that the MODULE option of ADD_LIBRARY does not handle such a flag.
Is there a portable solution to this problem with CMake?
Best regards,
Cédric Doucet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170309/61dbf8d8/attachment.html>
More information about the CMake
mailing list