CMake Associates a Shared Library with Static Libraries

I am migrating the AutoTools project to CMake.

What AutoTools does:

  • creates several static libraries
  • creates some shared libraries and static links to shared
  • creates an executable file, links it to shared libraries

What I managed to do with CMake:

  • create multiple static libraries - add_library(staticfoo <src>)
  • create several shared libraries - add_library(sharedfoo SHARED <src>)and link them -target_link_libraries(sharedfoo staticfoo)
  • create an executable file, link it to shared libraries - target_link_libraries(exe sharedfoo)but this again dragged the static libraries.

So, the resulting link for the executable file has static libraries in addition to the general ones. This does not match the command created by the AutoTools project.

target_link_libraries(sharedfoo PRIVATE staticfoo), lib .

"" ?

( )

+3
4

, CMake STATIC SHARED.

staticfoo / ,

add_library(staticfoo OBJECT <src>)

- :

add_library(sharedfoo SHARED <src> $<TARGET_OBJECTS:staticfoo>)

. add_library.

+3

, :

  • , w/ -fPIC, ( )
  • , , , , ,
  • , , , PRIVATE <static libs> , libs
+2

, , : https://github.com/CarloWood/cmaketest

, "", , , , .

@ VISIBILITY, @Zaufi.

- ( ) - __EXPORT, . , - , .

+1

. /WHOLEARCHIVE, -all_load --whole-archive .

0

All Articles