Hi,

Shared libraries required position independent code (PIC) for objects.
By default, in CMake, static libraries objects are not compiled with this mode… 
So your problem.

The easiest solution is to add this line to your CMakeLists.txt file:
Set (CMAKE_POSITION_INDEPENDENT_CODE ON)

Marc




On 17/11/15 11:44, "CMake on behalf of houssen" <cmake-boun...@cmake.org on 
behalf of hous...@ipgp.fr> wrote:

>Hello,
>
>How to link archives (.a) into shared object (.so) with cmake ?
>
>I have an archive:
>ADD_LIBRARY ( myArchive STATIC ${SRC} )
>That I need to link with a shared object:
>ADD_LIBRARY ( mySharedObject SHARED ${SRC} )
>TARGET_LINK_LIBRARIES ( mySharedObject PUBLIC myArchive )
>I get a compilation error that says "you need to compile with -fPIC !"
>
>As far as I understand, I need to use "-Wl,--whole-archive" : 
>http://stackoverflow.com/questions/7935421/linking-archives-a-into-shared-object-so...
> 
>But I can't figure out how to do that with CMake. Could someone help ?
>
>Franck
>-- 
>
>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
-- 

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 via email to