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...)
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/…
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With