# Header file of package not found.

**URL:** https://discourse.cmake.org/t/header-file-of-package-not-found/8680
**Category:** Code
**Tags:** os:windows, comp:msvc
**Created:** [August 5, 2023, 1:13am UTC](https://discourse.cmake.org/t/header-file-of-package-not-found/8680 "2023-08-05T01:13:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![LucasMSpereira](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lucasmspereira/32/3677_2.png) [@LucasMSpereira](https://discourse.cmake.org/u/LucasMSpereira)
#### Post date: [August 5, 2023, 1:13am UTC](https://discourse.cmake.org/t/header-file-of-package-not-found/8680/1 "2023-08-05T01:13:36Z")

</div>

On windows 10 (MSVC build toolset without Visual Studio), I’m trying to build my C++ project, which uses one package (for plotting): [Matplot++](https://github.com/alandefreitas/matplotplusplus). I cloned it’s repo in my project’s folder.

In my project’s main.cpp, I’m able to `#include <matplot/matplot.h>` and plot things. But when trying to do the same in a module (knn), this include directive results in an error during knn.cpp compilation (using vcpkg leads to the same result):

```auto
[project folder]\knn\knn.cpp(1,10): fatal error 
C1083: Cannot open include file: 'matplot/matplot.h': No such file or
directory [[project folder]\build\knn\knn.vcxproj]

```

My project’s CMakeLists.txt looks like this:

```auto
cmake_minimum_required(VERSION 3.5.0)
project(ml_cpp VERSION 0.1.0 LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_subdirectory(matplotplusplus)

add_subdirectory(knn)
add_subdirectory(kmeans)
add_subdirectory(lib)

add_executable(mlCPP src/main.cpp)

target_link_libraries(mlCPP PUBLIC knn kmeans lib)
target_link_libraries(mlCPP PRIVATE Matplot++::matplot)

target_include_directories(mlCPP PUBLIC
  "${CMAKE_HOME_DIRECTORY}/include"
  "${CMAKE_HOME_DIRECTORY}/knn/include"
  "${CMAKE_HOME_DIRECTORY}/kmeans/include"
)

```

And the project folder contains the following folders and files:

- build
- include: coheir.h, data\_handler.h, data.h
- kmeans: CMakeLists.txt, kmeans.cpp, kmeans.h
- knn: CMakeLists.txt, knn.cpp, knn.h
- lib: CMakeLists.txt, coheir.cpp, data\_handler.cpp, data.cpp
- matplotplusplus
- src: main.cpp
- CMakeLists.txt

What is the problem? How do I fix this?

---

<div class="post-metadata">

### Author: ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)
#### Post date: [August 5, 2023, 9:21am UTC](https://discourse.cmake.org/t/header-file-of-package-not-found/8680/2 "2023-08-05T09:21:10Z")

</div>

If that “knn” is also a target (_seems to be a library_), then it would also need `target_include_directories()` with Matplot headers (_or just linking to Matplot library, since that seems to be enough for “mlCPP” target_).

---

<div class="post-metadata">

### Author: ![LucasMSpereira](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lucasmspereira/32/3677_2.png) [@LucasMSpereira](https://discourse.cmake.org/u/LucasMSpereira)
#### Post date: [August 5, 2023, 12:10pm UTC](https://discourse.cmake.org/t/header-file-of-package-not-found/8680/3 "2023-08-05T12:10:03Z")

</div>

You are right! `target_include_directories()` didn’t solve it (at least not how I used it). But knn is a library. This module’s CMakeLists.txt only included `add_library(knn ./knn.cpp)` until now. And adding a second line with `target_link_libraries(knn PUBLIC Matplot++::matplot)` solved my problem.

I was stuck in this problem for days… thank you so much!
