# installing a hpp file for reuse in a ubuntu laptop

**URL:** <https://discourse.cmake.org/t/installing-a-hpp-file-for-reuse-in-a-ubuntu-laptop/11666>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [September 13, 2024, 3:35am UTC](https://discourse.cmake.org/t/installing-a-hpp-file-for-reuse-in-a-ubuntu-laptop/11666 "2024-09-13T03:35:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Dawsa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jonathan_dawsa/32/3695_2.png) [@Jonathan\_Dawsa](https://discourse.cmake.org/u/Jonathan_Dawsa)\
**Post date:** [September 13, 2024, 3:35am UTC](https://discourse.cmake.org/t/installing-a-hpp-file-for-reuse-in-a-ubuntu-laptop/11666/1 "2024-09-13T03:35:51Z")

</div>

I wanna know how to install a header files on the computer the header file called ihead5.hpp is like this `#include   
#include

using namespace std; //

void i5 (int a1,string s1) { /// a simple test fuction

cout \<\< 20 \<\<s1;

}

`

and the cmakelists.txt is like this : cmake\_minimum\_required(VERSION 3.28.3) # this is a practice CmakeLists to learn to install headers file in the computer

project(itest5 CXX ) # project name and version

set(CMAKE\_EXPORT\_COMPILE\_COMMANDS)

set(BUILD\_BUNDLE\_DIR “${PROJECT\_BINARY\_DIR}/lib”)

set(CMAKE\_INSTALL\_PREFIX “${BUILD\_BUNDLE\_DIR}” CACHE PATH “…” FORCE)

add\_library(ihead5 ihead5.hpp )

set\_target\_properties(ihead5 PROPERTIES LINKER\_LANGUAGE CXX) # set targets property

include(GNUInstallDirs) #include gnuinstalldir

install(TARGETS ihead5

EXPORT ihead5

ARCHIVE DESTINATION lib) # ihead goes to lib file

install(FILES

EXPORT ihead5.hpp

DESTINATION include) # ihead.hpp goes to include folder but i get thew error when using install command on vscode : `[main] Building folder: /home/d22/cmake_oef1/lib1/installtest1/build install [build] Starting build [proc] Executing command: /usr/bin/cmake --build /home/d22/cmake_oef1/lib1/installtest1/build --config Debug --target install -- [build] [1/1 0% :: 0.000] Install the project... [build] -- Install configuration: "Debug" [build] -- Up-to-date: /home/d22/cmake_oef1/lib1/installtest1/build/lib/lib/libihead5.a [build] CMake Error at cmake_install.cmake:50 (file): [build] file INSTALL cannot find "/home/d22/cmake_oef1/lib1/installtest1/EXPORT": [build] No such file or directory. [build] [build] [build] FAILED: CMakeFiles/install.util [build] cd /home/d22/cmake_oef1/lib1/installtest1/build && /usr/bin/cmake -P cmake_install.cmake [build] ninja: build stopped: subcommand failed. [proc] The command: /usr/bin/cmake --build /home/d22/cmake_oef1/lib1/installtest1/build --config Debug --target install -- exited with code: 1 [driver] Build completed: 00:00:00.023 [build] Build finished with exit code 1 ` Can someone help?

> Blockquote

---

<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:** [September 13, 2024, 9:50am UTC](https://discourse.cmake.org/t/installing-a-hpp-file-for-reuse-in-a-ubuntu-laptop/11666/2 "2024-09-13T09:50:48Z")

</div>

I can barely see where the code starts/ends and where your own text ends/starts, so your post would certainly benefit from having a proper formatting.

As for installing single files, that can be done with `install(FILES ... DESTINATION ...)`, although in case of installing public headers it is better to be handled with `install(TARGETS ... PUBLIC_HEADER DESTINATION ...)`, but for that to work you would need to set the [PUBLIC\_HEADER](https://cmake.org/cmake/help/latest/prop_tgt/PUBLIC_HEADER.html) target property.

> ihead goes to lib file

You seem to be creating a header-only library, so I doubt that this would work the way you expect it to.

---

<div class="post-metadata">

**Author:** ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)\
**Post date:** [September 13, 2024, 10:00am UTC](https://discourse.cmake.org/t/installing-a-hpp-file-for-reuse-in-a-ubuntu-laptop/11666/3 "2024-09-13T10:00:41Z")

</div>

For me the error comes from your call to `install(TARGETS ihead5 EXPORT ihead5 ARCHIVE DESTINATION lib)` because you’re mixing two different signatures.

See: [https://cmake.org/cmake/help/latest/command/install.html](https://cmake.org/cmake/help/latest/command/install.html)

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [September 13, 2024, 6:37pm UTC](https://discourse.cmake.org/t/installing-a-hpp-file-for-reuse-in-a-ubuntu-laptop/11666/4 "2024-09-13T18:37:09Z")

</div>

You will find a fully working modern example at:  
[CMake-Best-Practices—2nd-Edition/…/CMakeLists.txt](https://github.com/ClausKlein/CMake-Best-Practices---2nd-Edition/blob/feature/format-cpp-code/chapter04/ex05_config_file_package/CMakeLists.txt)

---

<div class="post-metadata">

**Author:** ![Jonathan\_Dawsa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jonathan_dawsa/32/3695_2.png) [@Jonathan\_Dawsa](https://discourse.cmake.org/u/Jonathan_Dawsa)\
**Post date:** [September 16, 2024, 11:30am UTC](https://discourse.cmake.org/t/installing-a-hpp-file-for-reuse-in-a-ubuntu-laptop/11666/5 "2024-09-16T11:30:11Z")

</div>

i sort kinda fix it by typing in the cmake this :

```auto

```

cmake\_minimum\_required(VERSION 3.22)  
project(itest5 CXX ) # project name and version

set(CMAKE\_EXPORT\_COMPILE\_COMMANDS)

add\_library(ihead5 INTERFACE ihead5.hpp )

target\_sources(ihead5 PUBLIC  
ihead5.hpp ) # set targets property  
set\_target\_properties(ihead5 PROPERTIES LINKER\_LANGUAGE CXX)  
include(GNUInstallDirs) #include gnuinstalldir

install(FILES ihead5.hpp DESTINATION lib) # goes to the lib files

install(FILES ihead5.hpp DESTINATION /usr/include) # goes to the /usr/include folder

install(FILES ihead5.hpp DESTINATION /usr/bin) # goes to the /usr/include folder

```auto
and now it finds the header in the cpp file i use for testing called ihead5test.cpp : 

```

#include \<ihead5.hpp\>

int main() {

i5(“hello h6”); // is the function of the ihead5.hpp file

}

```auto
but if try to add the hpp in a other CMakeList.txt :

```

cmake\_minimum\_required(VERSION 3.22.1)  
project(libtest1) # a project to test header files in other folders

include\_directories(include)

# find\_library(ihead5 required) # but if i do add

#this find\_library function it cannot find it

add\_executable(ihead5test ihead5test.cpp) # it can be executed but

# without mentiononing the ihead5.hpp file int CMakeLists.txt

```auto

target_link_libraries(ihead5test ihead5)

```

i get this errors :

```auto
[{
	"resource": "/home/jonathan/Documents/cpp.test/Cmake_practice/biebtest/CMakeLists.txt",
	"owner": "cmake-configure-diags",
	"severity": 8,
	"message": "CMake Error at CMakeLists.txt:7 (add_library):Cannot find source file:\n\n ihead5.hpp",
	"source": "CMake (add_library)",
	"startLineNumber": 7,
	"startColumn": 1,
	"endLineNumber": 7,
	"endColumn": 10000
}]

```

and : `[{ "resource": "/home/jonathan/Documents/cpp.test/Cmake_practice/biebtest/CMakeLists.txt", "owner": "cmake-configure-diags", "severity": 8, "message": "CMake Error at CMakeLists.txt:7 (add_library):No SOURCES given to target: ihead5", "source": "CMake (add_library)", "startLineNumber": 7, "startColumn": 1, "endLineNumber": 7, "endColumn": 10000 }]`  
do you know what i might do wrong?
