<html><body><div style="font-family: times new roman, new york, times, serif; font-size: 12pt; color: #000000"><div><br></div><div>Hello,</div><div><br></div><div>I am trying to find a portable way of generating modules with CMake.</div><div>Here is a toy CMake script:</div><div><br></div><div>-------------------------------</div><div></div><div><p style="margin: 0px;" data-mce-style="margin: 0px;">CMAKE_MINIMUM_REQUIRED(VERSION 2.8)</p><p style="margin: 0px;" data-mce-style="margin: 0px;"><br></p><p style="margin: 0px;" data-mce-style="margin: 0px;">PROJECT(dlopen_example CXX)</p><p style="margin: 0px;" data-mce-style="margin: 0px;"><br></p><p style="margin: 0px;" data-mce-style="margin: 0px;">ADD_EXECUTABLE(main main.cpp print_ref.cpp)<br>TARGET_LINK_LIBRARIES(main dl)</p><p style="margin: 0px;" data-mce-style="margin: 0px;"><br>ADD_LIBRARY(module MODULE module.cpp)</p><p style="margin: 0px;" data-mce-style="margin: 0px;">-------------------------------</p></div><div><br></div><div>This script works fine with g++ on Linux Ubuntu.</div><div>However, I get an error message with clang on Mac OSX:</div><div><br></div><div>----------------------------</div><div><p style="margin: 0px;" data-mce-style="margin: 0px;">Undefined symbols for architecture x86_64:<br> "print_ref()", referenced from:<br> _module in module.cpp.o<br>ld: symbol(s) not found for architecture x86_64<br>clang: error: linker command failed with exit code 1 (use -v to see invocation)<br>make[2]: *** [libmodule.so] Error 1<br>make[1]: *** [CMakeFiles/module.dir/all] Error 2<br>make: *** [all] Error 2</p><p style="margin: 0px;" data-mce-style="margin: 0px;">----------------------------</p><p style="margin: 0px;" data-mce-style="margin: 0px;"><br></p><p style="margin: 0px;" data-mce-style="margin: 0px;">I found a solution to this problem by adding the 'undefined dynamic_lookup' flag :</p><p style="margin: 0px;" data-mce-style="margin: 0px;"><br></p><p style="margin: 0px;" data-mce-style="margin: 0px;">SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -undefined dynamic_lookup")</p><p style="margin: 0px;" data-mce-style="margin: 0px;"><br></p><p style="margin: 0px;" data-mce-style="margin: 0px;">But, I am surprised that the MODULE option of ADD_LIBRARY does not handle such a flag.</p><p style="margin: 0px;" data-mce-style="margin: 0px;"><br></p><p style="margin: 0px;" data-mce-style="margin: 0px;">Is there a portable solution to this problem with CMake?</p><p style="margin: 0px;" data-mce-style="margin: 0px;"><br></p><p style="margin: 0px;" data-mce-style="margin: 0px;">Best regards,</p><p style="margin: 0px;" data-mce-style="margin: 0px;"><br></p><p style="margin: 0px;" data-mce-style="margin: 0px;">Cédric Doucet</p><p style="margin: 0px;" data-mce-style="margin: 0px;"><br></p><p style="margin: 0px;" data-mce-style="margin: 0px;"><br></p><p style="margin: 0px;" data-mce-style="margin: 0px;"><br></p></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div></body></html>