[CMake] Add libraries to end of compilation line ...

Angeliki Chrysochou angeliki.chrysochou at gmail.com
Thu Jun 26 04:16:29 EDT 2014


Hi Michael,

I think what matters is the correctly set dependencies for your build to
succeed (target_link_libraries). By "statically link" you mean you link
against static libraries that were before shared objects, right? This
should, to my knowledge, not have any influence to how you use
target_link_libraries.

My assumption would be that maybe these static libraries are not set as
linking dependencies to all necessary target_link_libraries.

If I understood your problem correctly, if you want to have a set of
libraries that are linking dependencies to all your libraries, you could
use the following approach: set a variable (list or simple) in your top
level CMakeLists.txt file, and then by default add it to all
target_link_libraries. You could modify these "global dependencies" or even
have this variable empty with no problems.

For example your top level CMakeLists.txt could contain:

set(GLOBAL_LIBRARIES "LibA.so" "LibB.so")

and then have this in the CMakeLists.txt files of the rest of your
libraries:

target_link_libraries(${YOUR_LIB}
${GLOBAL_LIBRARIES}
...
)

Maybe there is some better practice out there for this, if so, I would also
be interested to know :)

Cheers!
Angeliki





On Wed, Jun 25, 2014 at 7:46 PM, Michael Burns via CMake <cmake at cmake.org>
wrote:

> Hello, all.
>
> I work on a cross-platform project that has many libraries and several
> applications. CMake on Linux naturally adds the TARGET_LINK_LIBRARIES
> specified in the libraries after those specified in the
> TARGET_LINK_LIBRARIES for the application. However, there are several
> common system libraries, for example pthread, that are used by many of
> the libraries and most of the applications.
>
> The current scripts only have the common system libraries specified in a
> few scattered places. And, it works. However, we're trying to change to
> statically link these libraries and the links are failing with
> "undefined reference" errors. When I manually modify link.txt to add the
> various system libraries to the end of the compilation line, it works.
> So, rather than going through all of the scripts (of which there are
> many), I would like to be able to list them so they are added to the end
> of every link.
>
> Is there a way to identify libraries in such a way that they are added
> to the end of the compilation line rather than having to add those
> libraries to every library and application that requires them?
>
> Thanks!
>
> Mike
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20140626/763cb523/attachment.html>


More information about the CMake mailing list