Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PUBLIC/PRIVATE linking #37

Open
ruslo opened this issue Dec 19, 2018 · 0 comments
Open

PUBLIC/PRIVATE linking #37

ruslo opened this issue Dec 19, 2018 · 0 comments
Labels

Comments

@ruslo
Copy link
Owner

ruslo commented Dec 19, 2018

cmake_minimum_required(VERSION 3.2)
project(foo)

add_library(foo foo.cpp)
target_compile_definitions(foo PUBLIC FOO_FEATURE)

add_library(baz_1 baz_1.cpp)
target_link_libraries(baz_1 PUBLIC foo) # Case 1

add_library(baz_2 baz_2.cpp)
target_link_libraries(baz_2 PRIVATE foo) # Case 2

add_executable(boo_1 boo_1.cpp)
target_link_libraries(boo_1 PRIVATE baz_1)

add_executable(boo_2 boo_2.cpp)
target_link_libraries(boo_2 PRIVATE baz_2)
/usr/bin/c++ -DFOO_FEATURE -o foo.cpp.o -c foo.cpp

/usr/bin/c++ -DFOO_FEATURE -o baz_1.cpp.o -c baz_1.cpp
/usr/bin/c++ -DFOO_FEATURE -o boo_1.cpp.o -c boo_1.cpp # FOO_FEATURE added, foo headers can be used in boo_1.cpp
/usr/bin/c++ boo_1.cpp.o -o boo_1 libbaz_1.a libfoo.a  # libfoo.a added, linking is static, we may need symbols

/usr/bin/c++ -DFOO_FEATURE -o baz_2.cpp.o -c baz_2.cpp
/usr/bin/c++ -o boo_2.cpp.o -c boo_2.cpp               # FOO_FEATURE is missing, can't use foo headers in boo_2.cpp
/usr/bin/c++ boo_2.cpp.o -o boo_2 libbaz_2.a libfoo.a  # libfoo.a added even if PRIVATE used
@ruslo ruslo added the example label Dec 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant