Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is default target_link_libraries privacy setting?

Tags:

c++

cmake

I wonder what is the default target_link_libraries privacy.

I added line in CMake:

target_link_libraries(myTarget
        libraryA
        libraryB
        )

But I don't know if it is PRIVATE or PUBLIC or maybe INTERFACE. I check documentation, but I don't see answer for my question :(

Edit:

I found sth:

As a final note, if you call target_link_libraries() and do not specify any of PRIVATE, PUBLIC or INTERFACE, you may be tempted to believe that it will be treated as PUBLIC. The situation is actually more complicated than that though. It may be treated as PUBLIC or PRIVATE, depending on what other target_link_library() calls and/or target property manipulations have been performed. The documentation for target_link_libraries() talks a bit about this, but you have to go digging into the documentation for the target properties it mentions to get an understanding of what circumstances lead to PRIVATE or PUBLIC behaviour.

What circumstances? (BTW. Author of this words is Craig Scott that seems to be active user of SO, I belive he can answer to me...)

like image 345
BartekPL Avatar asked Jul 18 '18 07:07

BartekPL


People also ask

What is target_link_libraries?

target_link_libraries is responsible for adding a library into the linker's command line. If you use some library but doesn't specify it for the linker, you will got an "undefined reference" (or an "unresolved externals") error when create an executable or a shared library: stackoverflow.com/questions/12573816/…

What is Interface CMake?

Refer:CMake-Public-Private-Interface. PUBLIC. All the objects following PUBLIC will be used for linking to the current target and providing the interface to the other targets that have dependencies on the current target. PRIVATE. All the objects following PRIVATE will only be used for linking to the current target.


1 Answers

Description of policy 0023 suggests, that there is no "default" behavior of target_link_libraries - every single project should have calls to this command either all-keyworded or none-keyworded:

Plain and keyword target_link_libraries signatures cannot be mixed.

like image 133
Tsyvarev Avatar answered Sep 26 '22 19:09

Tsyvarev