Phase 2 commits - cmake link interface

Ralf Habacker ralf.habacker at freenet.de
Mon Aug 24 10:41:33 BST 2020


Am 24.08.20 um 05:47 schrieb Prasun Kumar:
>     target_link_libraries(ktoblzcheck PRIVATE stdc++ ${LIBS} 
> 
> 
> What does 'PRIVATE' do here? The docs say " Libraries and targets 
> following |PRIVATE| are linked to, but are not made part of the link 
> interface."
> which I didn't fully understand.
> 
I quote from 
https://cmake.org/cmake/help/latest/command/target_link_libraries.html

The PUBLIC, PRIVATE and INTERFACE keywords can be used to specify both 
the link dependencies and the link interface in one command. Libraries 
and targets following PUBLIC are linked to, and are made part of the 
link interface. Libraries and targets following PRIVATE are linked to, 
but are not made part of the link interface. Libraries following 
INTERFACE are appended to the link interface and are not used for 
linking <target>.

The link interface of a target is used by cmake to find out definitions 
and libraries required to link a library or executable which depends on 
a given target. See 
https://cmake.org/cmake/help/v3.7/prop_tgt/LINK_INTERFACE_LIBRARIES.html 
for more details.

If stdc++ would be added PUBLIC, then any client following the how to 
"Using ktoblzcheck" at 
https://sourceforge.net/p/ktoblzcheck/code/ci/master/tree/README.md 
would also link to stdc++ by default, which is not wanted except the 
case that the public api of ktoblzcheck uses some structures/classes 
from stdc++, which requires that clients must link to stdc++ to avoid 
undefined symbol errors or similar.

Regards
Ralf


More information about the Kde-finance-apps mailing list