0

Looking to compile both project.a and project.so libs and according to https://cgold.readthedocs.io/en/latest/tutorials/libraries/static-shared.html, the proper way to make a shared/staic library is...

set (LIB_NAME project)

set (FILE_NAMES
    a.cc
    b.cc
    c.cc
    d.cc
)

option(BUILD_SHARED_LIBS "Build shared libraries (.a/.so) instead of static ones (.lib/.a)" ON)

# Makes project.so but not project.a but should make both.
add_library(${LIB_NAME}
    ${FILE_NAMES}
)

Yet this is only making the project.so and not the project.a as well.

Now I can use the below workaround but this isnt how I should be doing it from what I am reading online.

set (LIB_NAME_SHARED project_shared)
set (LIB_NAME_STATIC project_static)

# Makes project_static.a
add_library(${LIB_NAME_STATIC} STATIC
    ${FILE_NAMES}
)

# Makes project_shared.so
add_library(${LIB_NAME_SHARED} SHARED
    ${FILE_NAMES}
)

Am I misunderstanding something here or can someone point me to whats possibly going on please and thanks!

Arcath
  • 51
  • 6
  • 1
    I don't think you will get shared + static. It's most likely a case of shared or static. Related: [https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html) ***If present and true, this will cause all libraries to be built shared unless the library was explicitly added as a static library. This variable is often added to projects as an option() so that each user of a project can decide if they want to build the project using shared or static libraries.*** – drescherjm Oct 26 '21 at 14:55
  • 1
    The [tutorial](https://cgold.readthedocs.io/en/latest/tutorials/libraries/static-shared.html) you links to explicitly notes, that for creating two types of the library the project should be **built twice**: once with option `-DBUILD_SHARED_LIBS=ON` and once without it (by default `BUILD_SHARED_LIBS` is OFF). – Tsyvarev Oct 26 '21 at 15:45

0 Answers0