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

houssen houssen at ipgp.fr
Tue Nov 17 05:44:01 EST 2015


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


More information about the CMake mailing list