# c++ library with cmake

**URL:** <https://discourse.cmake.org/t/c-library-with-cmake/9322>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [October 31, 2023, 3:44pm UTC](https://discourse.cmake.org/t/c-library-with-cmake/9322 "2023-10-31T15:44:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![superdu](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@superdu](https://discourse.cmake.org/u/superdu)\
**Post date:** [October 31, 2023, 3:44pm UTC](https://discourse.cmake.org/t/c-library-with-cmake/9322/1 "2023-10-31T15:44:09Z")

</div>

Hello every one,

I’m doing my first library (shared and static) in C++ with cmake.  
The idea is i could just compile it and install it as all other libraries to include it to other projects

My project have this structure.

|-root  
| | - data\_structure  
| | | - CMakeLists.txt  
| | | - enums.h  
| | | - exceptions.cpp  
| | | - exceptions.h  
| | | - point.cpp  
| | | - point.h  
| |  
| | - exemples  
| | | - CMakeLists.txt  
| | | - ex1.cpp  
| |  
| | - optimizer  
| | | - CMakeLists.txt  
| | | - utils.h  
| | | - utils.cpp  
| | | - local\_research  
| | | | - CMakeLists.txt  
| | | | - local\_research.cpp  
| | | | - local\_research.h  
|  
| - CMakeLists.txt

My problem is i dont know what to write in my cmakelists. I tried several things but that fail all time. what will be the minimal code that i have to write in all my CMakeLists to get an installable librairy ?

Thank you in advance

---

<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:** [October 31, 2023, 5:47pm UTC](https://discourse.cmake.org/t/c-library-with-cmake/9322/2 "2023-10-31T17:47:17Z")

</div>

Here’s [one example](https://github.com/retifrav/cmake-cpack-example). But do pay attention to the issues listed in the README.
