Difference between linking external built and installed library


In my project A I use ExternalProject_Add function to build some third party library B and then I’m going to use this library inside my project A.

I guess there two options are available:

  1. build B lib
  2. build and install B lib

and then somehow link built or installed library B inside A project.

For few days I’ve been trying to follow the first option but the command find_package(HDF5 REQUIRED) used to fail (the error tells me that hdf5-config.cmake searches for a /bin folder in unexisted folder).

Now I think I should rather build-install HDF5 and that should solve my problem.

The questions: is there a difference how developpers usually link external libraries to the target: do they build only or build-install those external libs?
Is there a difference how those libraries are linked to the target depending on each build and build-install option?

Using ExternalProject to build project A and your own add_library/add_executable calls using the outputs of A is not well-supported. I suggest making your own project another ExternalProject_add call in the top-level so that it can use find_package during its configure time (knowing that the other external project will make it available first).

Cc: @craig.scott

1 Like

Mixing ExternalProject_Add() with other parts of your main project that build things directly can be quite inconvenient. You will likely end up having to hard-code names/locations of things instead of being able to let CMake find them. Ben’s suggestion of moving your own project’s code into its own ExternalProject_Add() is the more typical way to structure things when some parts must be built that way (basically if some parts need to be built via ExternalProject, make everything be built via ExternalProject). This would be the more conventional “superbuild” structure.

1 Like

Thank you very much

I will follow your suggestion