0

I have a library which depends on multiple OBJECT libraries, defined like this:

add_library(openfastlib STATIC
  src/FAST_Library.f90
  $<TARGET_OBJECTS:openfast_prelib_obj>
  $<TARGET_OBJECTS:maplib_obj>
  $<TARGET_OBJECTS:nwtclibs_obj>
  $<TARGET_OBJECTS:ifwlib_obj>
  $<TARGET_OBJECTS:aerodynlib_obj>
  $<TARGET_OBJECTS:aerodyn14lib_obj>
  $<TARGET_OBJECTS:servodynlib_obj>
  $<TARGET_OBJECTS:elastodynlib_obj>
  $<TARGET_OBJECTS:beamdynlib_obj>
  $<TARGET_OBJECTS:subdynlib_obj>
  $<TARGET_OBJECTS:hydrodynlib_obj>
  $<TARGET_OBJECTS:orcaflexlib_obj>
  $<TARGET_OBJECTS:extptfm_mckflib_obj>
  $<TARGET_OBJECTS:openfoamtypeslib_obj>
  $<TARGET_OBJECTS:foamfastlib_obj>
  $<TARGET_OBJECTS:scdataextypeslib_obj>
  $<TARGET_OBJECTS:scdataexlib_obj>
  $<TARGET_OBJECTS:feamlib_obj>
  $<TARGET_OBJECTS:moordynlib_obj>
  $<TARGET_OBJECTS:icedynlib_obj>
  $<TARGET_OBJECTS:icefloelib_obj>
  $<TARGET_OBJECTS:openfast_postlib_obj>
  $<TARGET_OBJECTS:versioninfolib_obj>
)

target_link_libraries(openfastlib
  versioninfolib_obj
  openfast_prelib_obj
  maplib_obj
  nwtclibs_obj
  ifwlib_obj
  aerodynlib_obj
  aerodyn14lib_obj
  servodynlib_obj
  elastodynlib_obj
  beamdynlib_obj
  subdynlib_obj
  hydrodynlib_obj
  orcaflexlib_obj
  extptfm_mckflib_obj
  openfoamtypeslib_obj
  foamfastlib_obj
  scdataextypeslib_obj
  scdataexlib_obj
  feamlib_obj
  moordynlib_obj
  icedynlib_obj
  icefloelib_obj
  openfast_postlib_obj
  versioninfolib_obj
  ${LAPACK_LIBRARIES}
  ${CMAKE_DL_LIBS}
)

Each object library is defined in a directory which is at the same level as this directory. There is also a top level cmake file for the project.

I also have an install command like this:

install(TARGETS openfastlib openfast_prelib openfast_postlib
  EXPORT ${CMAKE_PROJECT_NAME}Libraries
  RUNTIME DESTINATION lib
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib)

However, when I run cmake (version 3.22.2), I get:

CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "versioninfolib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "openfast_prelib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "maplib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "nwtclibs_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "ifwlib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "aerodynlib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "aerodyn14lib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "servodynlib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "elastodynlib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "beamdynlib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "subdynlib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "hydrodynlib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "orcaflexlib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "extptfm_mckflib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "openfoamtypeslib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "foamfastlib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "scdataextypeslib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "scdataexlib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "feamlib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "moordynlib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "icedynlib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "icefloelib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "openfast_postlib_obj" that is not in any export set.
CMake Error: install(EXPORT "OpenFASTLibraries" ...) includes target "openfastlib" which requires target "versioninfolib_obj" that is not in any export set.

Why am I getting this error, and how should I address it?

Incidentally this is a legacy code base I am working on, which I was modifying to build a library from object libraries, instead of linking together a bunch of other libraries which are also built and installed. The motivation was that I thought the previous method was resulting in missing symbols when making a static library.

The question install EXPORT problem for library with dependencies does not address this as it does not refer to OBJECT type libraries which on would not want to install, but rather only normal libraries.

crobar
  • 2,810
  • 4
  • 28
  • 46
  • 1
    What puzzles me, if you have added the `TARGET_OBJECTS` from all your `OBJECT` libraries to the static lib, why do you add the target libraries in the `target_link_libraries` command too? – vre Feb 11 '22 at 13:08
  • You got the error because you link (in non-PRIVATE manner) the target `openfastlib`, which is exported, to target `versioninfolib_obj` (and others) which is not exported. Instead of exporting object targets, consider to use PRIVATE linkage with them, or even remove that linkage, as vre suggests. – Tsyvarev Feb 11 '22 at 13:13
  • @Tsyvarev, I actually separately discovered I should be adding the object library to their own respective install targets. See the [kitware cmake gitlab issue here](https://gitlab.kitware.com/cmake/cmake/-/issues/18935). This solves the problem. They are then converted to INTERFACE libraries. – crobar Feb 11 '22 at 14:57
  • @vre, the answer to your question is that I developed this from a code which was linking actual built libraries to create the library. I take it I can delete them from the target_link_libraries now then. – crobar Feb 11 '22 at 14:59
  • @Tsyvarev, incidentally, I did see the linked question, but it is about real libraries not object libs, and I assumed I wouldn't want to be installing object libs, and a commenter even asks the question of an answer of what to do when you don't want to install the library. – crobar Feb 11 '22 at 15:05
  • "I assumed I wouldn't want to be installing object libs, and a commenter even asks the question of an answer of what to do when you don't want to install the library." - According to the [documentatoion](https://cmake.org/cmake/help/latest/command/install.html), CMake perfectly allows to install OBJECT libraries. If you mean [that comment](https://stackoverflow.com/questions/5378528/install-export-problem-for-library-with-dependencies#comment103643896_5379238), then its reply points to other question, which suggests PRIVATE linkage. I have added corresponding answer to the duplicate question. – Tsyvarev Feb 11 '22 at 15:53
  • As for [bugreport](https://gitlab.kitware.com/cmake/cmake/-/issues/18935) you refers to, a solution suggested by the developers (e.g. that one: https://gitlab.kitware.com/cmake/cmake/-/issues/18935#note_520410) is installing OBJECT library but without object files. According to latest [documentation](https://cmake.org/cmake/help/latest/command/install.html), this ability has been implemented. So the error with OBJECT libraries doesn't differ a lot from other kind of libraries: for overcome the error one need either to install the library or make the linkage PRIVATE. – Tsyvarev Feb 11 '22 at 16:06

0 Answers0