Help needed with '-whole-archive,-export-dynamic'

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Help needed with '-whole-archive,-export-dynamic'

David Aldrich-2
Hi

I am porting a gnu make project to CMake. Initially I am using the Ninja
generator and running in Ubuntu 18.04.

The project consists of a static library 'libKernel.a', which includes main.cpp,
which we link into an executable: 'MyApp'. The program dynamically loads shared
libraries that need objects from 'libKernel.a' so we use options such as
-whole-archive and -export-dynamic.

The original link command for the program is:

g++ -o _gnuRelease/MyApp -Wl,-whole-archive,-export-dynamic,--no-as-needed ../Kernel/_gnuRelease/libKernel.a -Wl,--as-needed,--no-whole-archive -lpthread -ldl

In CMake I have implemented this as:

add_executable(MyApp ../Kernel/main.cpp)
set_target_properties(MyApp PROPERTIES ENABLE_EXPORTS TRUE)
target_link_libraries(MyApp Kernel ${CMAKE_DL_LIBS})

and CMake's link command is:

/usr/bin/c++  -O3 -DNDEBUG  -Wl,--export-dynamic -rdynamic CMakeFiles/MyApp.dir/Kernel/main.cpp.o  -o release/MyApp  Kernel/libKernel.a -ldl

The CMake build is failing to link at runtime as some symbols are missing.

I have two issues here:

1) In the CMake implementation I removed main.cpp from libKernel and specified
it as the executable source file, as it seems that the executable needs at
least one SOURCE file.  Is there a way around this?

2) How can I tell CMake to use the '-Wl,-whole-archive,-export-dynamic,--no-as-needed' flags?

Best regards

David

--

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:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Fwd: Help needed with '-whole-archive,-export-dynamic'

David Aldrich-2
Just to say, I have fixed this problem, so no help needed now.

--

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:
https://cmake.org/mailman/listinfo/cmake