Quantcast

Missing 'undefined dynamic_lookup' flag

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Missing 'undefined dynamic_lookup' flag

Cedric Doucet

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
















--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Missing 'undefined dynamic_lookup' flag

Cedric Doucet

Actually, I should not modify CMAKE_CXX_COMPILER_FLAGS.
It seems that the problem comes from the variable CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS which only contains '-bundle -Wl,-headerpad_max_install_names' but not '-undefined dynamic_lookup'.

How to overcome this problem?



De: "Cedric Doucet" <[hidden email]>
À: [hidden email]
Envoyé: Jeudi 9 Mars 2017 23:41:03
Objet: Missing 'undefined dynamic_lookup' flag


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

















--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Missing 'undefined dynamic_lookup' flag

CMake mailing list
Hello,

On 3/10/17 12:31 AM, Cedric Doucet wrote:
> Actually, I should not modify CMAKE_CXX_COMPILER_FLAGS.
> It seems that the problem comes from the variable CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS which only contains ' -bundle -Wl,-headerpad_max_install_names' but not ' -undefined dynamic_lookup'.

Please try:

TARGET_LINK_LIBRARIES(main "-undefined dynamic_lookup")

Thanks,
Gregor
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Missing 'undefined dynamic_lookup' flag

CMake mailing list
On 3/12/17 6:45 PM, Gregor Jasny wrote:
> On 3/10/17 12:31 AM, Cedric Doucet wrote:
>> Actually, I should not modify CMAKE_CXX_COMPILER_FLAGS.
>> It seems that the problem comes from the variable CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS which only contains ' -bundle -Wl,-headerpad_max_install_names' but not ' -undefined dynamic_lookup'.
>
> Please try:
>
> TARGET_LINK_LIBRARIES(main "-undefined dynamic_lookup")

Meh. main should have been module. You could also try to add it to
CMAKE_SHARED_LINKER_FLAGS.

Thanks,
Gregor

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Loading...