[CMake] linking question

Petr Kmoch petr.kmoch at gmail.com
Thu Apr 16 02:53:34 EDT 2015


Hi Bill.

Probably the easiest way to set the interface properties to just what you
need is to use the PUBLIC (which is the default), PRIVATE and INTERFACE
keywords when specifying dependencies. In your case, you'd apply them like
this:

add_library(joe STATIC joe.c joe_a.c)
add_library(fred SHARED fred.c fred_a.c)
target_link_libraries(fred PRIVATE joe)  # PRIVATE means it will not form
part of the transitive linking interface

add_executable(mike mike.c)
# mike only contains calls to functions in fred
target_link_libraries(mike fred)

I hope this helps.

Petr


On Thu, Apr 16, 2015 at 12:07 AM, Bill Newcomb <bnewcomb at nvidia.com> wrote:

> The following is all on Linux (with gcc, gnu binutils, etc).
>
> I'm trying to build libfred.so that uses code from libjoe.a, but I want
> libfred.so to be complete, i.e. I don't want any program that I build that
> links to libfred.so also need libjoe.a.
>
> Then I want to build executable mike that is dynamically linked with
> libfred.so .  However, the link script for mike puts libjoe.a on the
> command line.
>
> add_library(joe STATIC joe.c joe_a.c)
> add_library(fred SHARED fred.c fred_a.c)
> target_link_libraries(fred joe)
>
> add_executable(mike mike.c)
> # mike only contains calls to functions in fred
> target_link_libraries(mike fred)
>
>
> The docs give me the impression that I should set the
> INTERFACE_LINK_LIBRARIES property on moo to override the inherited
> transitive dependencies, but setting it to "" has no effect.  Same for
> LINK_INTERFACE_LIBRARIES.
>
> Any idea how to make this work?
>
> Thanks,
> B.
>
> ------------------------------------------------------------
> -----------------------
> This email message is for the sole use of the intended recipient(s) and
> may contain
> confidential information.  Any unauthorized review, use, disclosure or
> distribution
> is prohibited.  If you are not the intended recipient, please contact the
> sender by
> reply email and destroy all copies of the original message.
> ------------------------------------------------------------
> -----------------------
> --
>
> 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/20150416/592d5625/attachment.html>


More information about the CMake mailing list