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
1
vote
3 answers

"Does not name a type" in header-only library

I'm trying to write a header-only library of helper functions for myself. (I'm using boost and SDL, and boost is much easier to use, so I want to emulate that for my own helper library.) I'm getting the error "Does not name a type" for one of my…
AngryPuffin
  • 35
  • 1
  • 6
1
vote
1 answer

Why can't I use C++ Eigen (header only lib) in two console apps within the same MS VS solution?

I made a Microsoft visual solution with two console app projects. I can use the Eigen library in one project by simply declaring it in the properties like so: $(ProjectDir)Eigen\eigen3; I can use library structures like "Eigen::Vector3d" etc no…
1
vote
2 answers

Using CGAL 4.12 header-only in a project

I'm working on a class project in C++ using CLION which requires the CGAL library, and I'm having trouble getting the library to work with my project. We're trying to get the library working in it's header-only configuration for simplicity, however…
1
vote
2 answers

how to include boost headers in own header-only library

i am using Jetbrains CLion 2017.3 and the bundled CMake version 3.9.6 with mingw64 5.0 version/g++ 7.1. Although reading the "Mastering CMake" ( i am new to CMake !) i have many difficulties to understand the basics. Since 3 days i am searching for…
user3664264
  • 31
  • 1
  • 3
1
vote
0 answers

CMake add single header only file to project

I specifically want to add stb_image_write.h to my project, but I am getting "multiple definition"errors when compiling using CMake. I include stb_image_write.h into one header file called "screen.h" and the includes are as followed: #include…
1
vote
1 answer

"Multiple definition of" error while writing a header-only template library

My project resembles this set up, when I need to use my_template_library.h in main_class.h. main.cpp #include "main_class.h" int main() { MainClass m; return m.exec(); } main_class.h #ifndef MAIN_CLASS_H #define MAIN_CLASS_H #include…
Flying Hat
  • 187
  • 3
  • 11
1
vote
1 answer

Can't get warnings to work for header-only library

I'm creating an header-only library, and I would like to get warnings for it displayed during compilation. However, it seems that only warnings for the "main" project including the library get displayed, but not for the library itself. Is there a…
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
0
votes
0 answers

Preventing namespace conflict from header-only library dependencies

I am developing a library component which can be used as a template-heavy header-only library. The library has its own namespace for all the functions it exports. My problem is that the library makes use of other header-only libraries, with their…
daedsidog
  • 1,732
  • 2
  • 17
  • 36
0
votes
0 answers

Building and adding several libraries with CMake

I am CMake newbie and trying to use it within a project of mine in order to learn it The project is a small game engine that use different external libraries such as GLFW, GLUT and SDL2. Some of them such as GL are in my os include directory and…
GrandJagon
  • 23
  • 3
0
votes
0 answers

Use header-only (+implementation .h files) across multiple files in C++ project

I have been trying to use this library in my C++ project for some time now and can't seem to figure out how to get around the issue of multiple definitions. The library contains only header files (and implementation header files) so the source…
0
votes
1 answer

CMake: add compile flag for header only library

Unsure about how to use CMake properly here. I have one library, which is a template header only library which uses C++20 features. Therefore, I want to make sure that any [downstream/consumer/dependent] of my library compiles the specialization of…
user93114
  • 61
  • 5
0
votes
1 answer

Facing problems in my first time handling CMake, Third party(header only) libraries

I want to use the following library https://github.com/gmeuli/caterpillar It's documentation says that it's a header-only library, and that I should "directly integrate it into my source files with #include ." It also…
0
votes
0 answers

CMAKE retain dir path for header includes from a header only built library

I'm trying to restructure my CMAKE project by placing all headers in a separate cmake header only project and add that using target_link_libraries to my sources cmake project. Is it possible to retain folder path while including headers in cpp…
0x52616A657368
  • 388
  • 3
  • 24
0
votes
0 answers

Implement printable class without paying for iostream compilation?

What is the correct way to implement a printable class in C++ if one wants to avoid processing iostream as much as possible? This question raises from the interaction between iostream, iosfwd with templates. 1. Traditional approach The traditional…
alfC
  • 14,261
  • 4
  • 67
  • 118
0
votes
1 answer

Global singleton in header-only C library

I am trying to implement a global singleton variable in the header-only library in C (not C++). So after searching on this forum and elsewhere, I came across a variation of Meyer's singleton that I am adapting to C here: /* File: sing.h */ …
Regus Pregus
  • 560
  • 3
  • 12