<html><body><div style="font-family: times new roman, new york, times, serif; font-size: 12pt; color: #000000"><div><br></div><div>Actually, I should not modify CMAKE_CXX_COMPILER_FLAGS.</div><div>It seems that the problem comes from the variable CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS which only contains '<span style="font-size: 12pt;">-bundle -Wl,-headerpad_max_install_names' but not '<span style="font-size: 16.3636360168457px;" data-mce-style="font-size: 16.3636360168457px;">-undefined dynamic_lookup'.</span></span></div><div><span style="font-size: 12pt;"><span style="font-size: 16.3636360168457px;" data-mce-style="font-size: 16.3636360168457px;"><br></span></span></div><div>How to overcome this problem?</div><div><br></div><div><br></div><hr id="zwchr"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>De: </b>"Cedric Doucet" <cedric.doucet@inria.fr><br><b>À: </b>cmake@cmake.org<br><b>Envoyé: </b>Jeudi 9 Mars 2017 23:41:03<br><b>Objet: </b>Missing 'undefined dynamic_lookup' flag<br><div><br></div><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;">CMAKE_MINIMUM_REQUIRED(VERSION 2.8)</p><p style="margin: 0px;"><br></p><p style="margin: 0px;">PROJECT(dlopen_example CXX)</p><p style="margin: 0px;"><br></p><p style="margin: 0px;">ADD_EXECUTABLE(main main.cpp print_ref.cpp)<br>TARGET_LINK_LIBRARIES(main dl)</p><p style="margin: 0px;"><br>ADD_LIBRARY(module MODULE module.cpp)</p><p 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;">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;">----------------------------</p><p style="margin: 0px;"><br></p><p style="margin: 0px;">I found a solution to this problem by adding the 'undefined dynamic_lookup' flag :</p><p style="margin: 0px;"><br></p><p style="margin: 0px;">SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -undefined dynamic_lookup")</p><p style="margin: 0px;"><br></p><p 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;"><br></p><p style="margin: 0px;">Is there a portable solution to this problem with CMake?</p><p style="margin: 0px;"><br></p><p style="margin: 0px;">Best regards,</p><p style="margin: 0px;"><br></p><p style="margin: 0px;">Cédric Doucet</p><p style="margin: 0px;"><br></p><p style="margin: 0px;"><br></p><p 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></blockquote><div><br></div></div></body></html>