# Issue about PRIVATE in target\_link\_libraries

**URL:** https://discourse.cmake.org/t/issue-about-private-in-target-link-libraries/6182
**Category:** Usage
**Tags:** os:windows
**Created:** [July 29, 2022, 4:01am UTC](https://discourse.cmake.org/t/issue-about-private-in-target-link-libraries/6182 "2022-07-29T04:01:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![FuXii](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/8baadc/32.png) [@FuXii](https://discourse.cmake.org/u/FuXii)
#### Post date: [July 29, 2022, 4:01am UTC](https://discourse.cmake.org/t/issue-about-private-in-target-link-libraries/6182/1 "2022-07-29T04:01:58Z")

</div>

I create a static lib project called `TCore` and dependent many thirdparty lib project :

- `glslang`
- `VulkanMemoryAllocator`
- `SPIRV-Cross`

```auto
project(TCore)

aux_source_directory(./src/ SRCS)

add_library(${PROJECT_NAME} STATIC ${SRCS})

add_subdirectory(./thirdparty)

target_include_directories(${PROJECT_NAME}
PUBLIC ./include
)

target_link_directories(${PROJECT_NAME} 
PRIVATE ./thirdparty/VulkanMemoryAllocator/src
PRIVATE ./thirdparty/glslang/glslang
PRIVATE ./thirdparty/glslang/glslang/OSDependent

PRIVATE ./thirdparty/glslang/hlsl
PRIVATE ./thirdparty/glslang/OGLCompilersDLL
PRIVATE ./thirdparty/glslang/SPIRV

PRIVATE ./thirdparty/SPIRV-Cross
)

target_link_libraries(${PROJECT_NAME}  
PRIVATE VulkanMemoryAllocator
PRIVATE glslang
PRIVATE OGLCompiler
PRIVATE OSDependent
PRIVATE SPIRV
PRIVATE spirv-cross-core
PRIVATE spirv-cross-glsl
PRIVATE spirv-cross-hlsl
)

```

And then I use this `TCore` lib to create executable app named `PureHelloTriangle`

```nohighlight
project(TSample)

set(INCLUDE_PARTH 
PUBLIC ../engine/framegraph/include 
PUBLIC ../engine/core/include
PUBLIC ../thirdparty/glm/
PUBLIC ../thirdparty/tinygltf/
PUBLIC ../thirdparty/imgui/
PUBLIC ../thirdparty/imgui/backends/
PUBLIC ../thirdparty/KTX-Software/include/
)

set(LINK_PARTH 
PUBLIC /engine/framegraph/ 
PUBLIC /engine/core/
PUBLIC /thirdparty/glfw/src/
PUBLIC /thirdparty/KTX-Software/
)

set(LIBS 
TCore ###<<<-- this TCore lib
TFrameGraph
glfw
ktx
)

add_executable(PureHelloTriangle ./PureHelloTriangle.cpp)
target_include_directories(PureHelloTriangle PUBLIC ${INCLUDE_PARTH})
target_link_directories(PureHelloTriangle PUBLIC ${LINK_PARTH})
target_link_libraries(PureHelloTriangle PUBLIC ${LIBS})

```

then use `CMake-GUI` to create `Visual Studio` project:

 ![1E9WMR24Y@P(WT8WDKL5)4](https://discourse.cmake.org/uploads/default/original/2X/f/fd6ab77cfcca28f8ad24ce206dd830ed035f4200.jpeg)

the question is: I have use `PRIVATE` in `target_link_libraries` to create `TCore` lib. Normally when I use `TCore` in `PureHelloTriangle` just link `TCore` is enough, but in `Visual Studio` the `PureHelloTriangle` also link the dependent library of `TCore`. Why?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [August 2, 2022, 11:28am UTC](https://discourse.cmake.org/t/issue-about-private-in-target-link-libraries/6182/2 "2022-08-02T11:28:19Z")

</div>

> [@FuXii](#):
>
> Why?

It’s how linking CMake targets works in general. This thread is very similar to your question:

> [@How do I configure a library so that the projects which depend upon it do not need to know about the projects upon which it depends?](https://discourse.cmake.org/t/how-do-i-configure-a-library-so-that-the-projects-which-depend-upon-it-do-not-need-to-know-about-the-projects-upon-which-it-depends/6107):
>
> I have Project A, a library, and Project B, an executable which depends on A. A and B are completely separate with regard to directory structure, build systems, etc. A depends on a third party library, X. As it happens in my case, A, B, and X all use CMake, but A is the only project under my control. How can I configure CMake for A so that B does not need to know about X? For the moment, B gets a linker error, and the only way that I can find to make that go away is to have B reference X, w…

---

<div class="post-metadata">

### Author: ![TripRichert](https://discourse.cmake.org/user_avatar/discourse.cmake.org/triprichert/32/2539_2.png) [@TripRichert](https://discourse.cmake.org/u/TripRichert)
#### Post date: [August 2, 2022, 12:51pm UTC](https://discourse.cmake.org/t/issue-about-private-in-target-link-libraries/6182/3 "2022-08-02T12:51:09Z")

</div>

private linking just means that cmake doesn’t propagate include paths and compiler flags

It doesn’t mean that linking to the library itself doesn’t propagate.
