[CMake] How to link archives (.a) into shared object (.so) with cmake ?

houssen houssen at ipgp.fr
Tue Nov 17 07:48:47 EST 2015


Unfortunately, that does not work !... But indeed, for me, it should 
have ?!...

Franck

Le 2015-11-17 12:34, CHEVRIER, Marc a écrit :
> 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-bounces at cmake.org on behalf of houssen at 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



More information about the CMake mailing list