Questions tagged [header-only]

In C or C++, a library is called header-only if the full definitions of all macros, functions and classes comprising the library are visible to the compiler in a header file form.

Header-only libraries do not need to be separately compiled, packaged and installed in order to be used. All that is required is to point the compiler at the location of the headers and then #include the header files into the application source.

The disadvantages include:

  • brittleness. Most changes to the library will require recompilation of all compilation units using that library
  • longer compilation times. The compilation unit must see the implementation of all components in the included files, rather than just their interfaces

The header-only form is popular because it avoids the problem of packaging.

87 questions
0
votes
2 answers

How to add a header only library to a project with cmake build system?

I need to modify a C++ project to use Cereal library. The build system of this project is based on CMake. Since Cereal is a header only library and also uses CMake, I expect this to be a pretty simple task. I tried editing the CMakeLists.txt…
Armut
  • 969
  • 8
  • 22
0
votes
0 answers

How to make a different target_include_directories for internal and external #includes for a header-only library in CMake?

The directory structure for my header-only library is as follows: proj/ include/ proj/ file1.h file2.h CMakeLists.txt Basically I would like to be able to do the following inside file1.h (and therefore…
0
votes
0 answers

CMAKE dependency on upstream C++ Header-only library

I have a relatively simple header-only C++ library with the following structure - apps - app - CMakeLists.txt - app.cpp - include CMakeLists.txt The library itself is in the root of the project and app1 is added afterwards. My intention…
xalpha
  • 446
  • 1
  • 5
  • 15
0
votes
0 answers

How to specify header-only boost library for CMake?

I am using the following cmake file cmake_minimum_required(VERSION 3.16) project(Translated01) find_package(Boost REQUIRED) find_package(OpenSSL REQUIRED) set(CMAKE_CXX_STANDARD 14) add_executable(Translated01 main.cpp) During CMake configure…
Dims
  • 47,675
  • 117
  • 331
  • 600
0
votes
0 answers

Linking a library to a header-only one

I have two libraries: a; b: a header-only library which depends on a. I am not sure if it is possible to link b to a. If so, how can I do it? In fact, I have a third library c that depends on both. This CMake script does not…
0
votes
0 answers

Can I hide the definitions in third-party header files?

I am writing a header-only library, using only .hpp and .ipp files. And I have to #include some standard libraries sometimes. But it becomes costly for the IDEs to parse everything and show the user for suggestions. I do not want to split my…
0
votes
2 answers

C++ how to call header-only library

I learnt C++17 way of dealing with header-only library, by adding inline keyword: #include #include using namespace std; struct C { static const inline string N {"abc"}; }; int main() { cout << C::N << endl; return…
Heifetz_Fan
  • 439
  • 1
  • 6
  • 15
0
votes
0 answers

Using precompiled header in a project that's already using header-only libraries?

I'm building a project and I wanted to make a precompiled header to boost performance. The issue is that I'm also using stbi_image headers in my project, which means I would have to include my header on all the stbi files in my project AND make sure…
Julk
  • 169
  • 7
0
votes
0 answers

Reduce binary size and compilation time when using a C++ header-only library

I'm creating a GDScript wrapper library using tiny-dnn C++ library as base. The issue is that tiny-dnn is header-only, and I have to include it in most of my library's .cpp files (after all, I'm creating a wrapper). This results in a compilation…
0
votes
0 answers

Cpp compilation techniques with header-only library

I notice my available memory going down to zero (from 12GB) when compiling a project including a header-only library (tiny-dnn). Following this is a system freeze. This seems to mostly occur when there is a compilation or a linker error (especially…
errolflynn
  • 641
  • 2
  • 11
  • 24
0
votes
1 answer

Inline function compilation

I intend to provide simple wrappers to the operating system API, which throw exceptions when errors happen. These wrappers are simple, and are all defined as inline functions in a header file. Since system API is supposed to be large, the header…
Lingxi
  • 14,579
  • 2
  • 37
  • 93
0
votes
0 answers

How to migrate from header-only project?

We have a header-only C++ code base (VS 2010, Eclipse, Makefile) with about 450 files (3.6 MB). Everyday work started to become harder because of long (4 minutes) compilation times. A smaller part of it, about 20%, is templated, but others are…
Notinlist
  • 16,144
  • 10
  • 57
  • 99
1 2 3 4 5
6