# Does a static library target not expose include directories?

**URL:** https://discourse.cmake.org/t/does-a-static-library-target-not-expose-include-directories/7371
**Category:** Usage
**Tags:** os:windows
**Created:** [January 31, 2023, 5:47pm UTC](https://discourse.cmake.org/t/does-a-static-library-target-not-expose-include-directories/7371 "2023-01-31T17:47:47Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![JuliusCaesar](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/85e7bf/32.png) [@JuliusCaesar](https://discourse.cmake.org/u/JuliusCaesar)
#### Post date: [January 31, 2023, 5:47pm UTC](https://discourse.cmake.org/t/does-a-static-library-target-not-expose-include-directories/7371/1 "2023-01-31T17:47:47Z")

</div>

Hey guys,  
I need to create static library, which itself links to other pre compiled static libraries  
My CMakeLists.txt to build this static lib looks like this

> set(MODULE\_LINK\_LIBS “”)  
> set(RESSOURCE\_FILES “”)  
> if(MSVC)  
> list(APPEND MODULE\_LINK\_LIBS  
> “${CMAKE\_CURRENT\_LIST\_DIR}/GUI/GUI.lib”  
> “${CMAKE\_CURRENT\_LIST\_DIR}/Simulation/GUISim.lib”  
> )  
> list(APPEND RESSOURCE\_FILES “Simulation/Simulation.res”)  
> endif()
> 
> #incude dirs  
> #interface include dirs need to contain the absolute path  
> set(INCLUDE\_PUBLIC\_DIRS  
> “${CMAKE\_CURRENT\_LIST\_DIR}/GUI/Include”  
> “${CMAKE\_CURRENT\_LIST\_DIR}/Config”  
> )  
> set(module\_name “myLib”)
> 
> add\_library(“${module\_name}” STATIC ${MODULE\_SOURCES})
> 
> target\_sources(${module\_name} PRIVATE ${RESSOURCE\_FILES})  
> target\_link\_libraries(${module\_name} PUBLIC ${MODULE\_LINK\_LIBS})
> 
> target\_include\_directories(“${module\_name}” PUBLIC “${INCLUDE\_PUBLIC\_DIRS}” )

now when I’m trying to consume this static library

> set(EXE\_NAME “libTest”)  
> set(MODULE\_SOURCES “main.c” )  
> add\_executable(${EXE\_NAME} ${MODULE\_SOURCES})  
> target\_link\_libraries(${EXE\_NAME} PRIVATE myLib)

the include Paths are missing  
#include \<GUI.h\> results in a file not found error.  
When i add #include \<GUI.h\> to my static library this paths is resolved correctly.

So does a static library target not expose the INCLUDE\_PUBLIC\_DIRS?

I’d prefer to remove the STATIC from add\_library(“${module\_name}” STATIC ${MODULE\_SOURCES}) . However when I’m doing that I’m getting some linker errors from unresolved symbols from GUI.lib and GUISim.lib. Not sure why this is happening though. Maybe you can’t mix dynamic and static libs ?!

Could you help me out here?

thx guys

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [February 5, 2023, 9:57pm UTC](https://discourse.cmake.org/t/does-a-static-library-target-not-expose-include-directories/7371/2 "2023-02-05T21:57:49Z")

</div>

Static libraries expose their non-PRIVATE include directories. I’m pretty sure this is a quoting issue in your CMake files.

> [@JuliusCaesar](#):
>
> target\_include\_directories(“${module\_name}” PUBLIC “${INCLUDE\_PUBLIC\_DIRS}” )

Quoting a variable which is a list will expand it like “a;b;c”. You shouldn’t be quoting `${INCLUDE_PUBLIC_DIRS}`.

When you build your software with verbose enabled you should see the `-I` will have an invalid directory path.
