94 questions
3 votes
1 answer
260 views
Using CMake, how can we check if ".h" files are "self-contained" (as per guidelines)?
There is the following C++ Core Guideline: Header files should be self-contained In large project, how can we automate this check, I would like to avoid having to add empty .cpp files for every &...
6 votes
1 answer
181 views
Good practices guidelines for `ffast-math`
I am writing C++ header-only library doing some floating-point math. Since the library is header-only I realized that the library user sooner or later will include it into his project where -ffast-...
1 vote
0 answers
147 views
Header-only library with CMake logic - how to treat in Conan?
I'm the author of a header-only library, which I want to make available via Conan. So, I'm writing a conanfile.py for it. The Conan documentation suggests a path for this, when your project is header ...
2 votes
0 answers
360 views
Linking error with g++ for static inline thread_local variable
I have three files I am compiling together using CMake (smallest example that produces the error): lib.h #ifndef lib #define lib struct StructOuter{ struct StructInner{ int a; ...
0 votes
1 answer
81 views
cmake: regular (SHARED) library depending on a header-only (INTERFACE) library
Include paths for header-only dependencies not propagating to non-header-only library targets. cmake 3.25.3, gcc 12.2.0. I have a header-only library, let's call it foo: # foo CMakeLists.txt ...
1 vote
1 answer
247 views
List all available Functions in C
I want to create Bindings for another programming language, and since there are hundreds of functions I am wondering how I can make things more efficient by automating or so. That means I want a list ...
2 votes
2 answers
2k views
How to make clangd to enable header-only library implementation
There is a way of distributing C/C++ libraries as a one header-only file. Library is in one library.h file: header declarations together with implementation hidden under #ifdef LIBRARY_IMPL. You need ...
0 votes
0 answers
164 views
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 ...
0 votes
0 answers
348 views
Building and adding several libraries with CMake [duplicate]
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 ...
5 votes
1 answer
2k views
Header only library as a module?
I'm authoring a templated header only library. It has no state, no global variables, no .cpp that needs to be compiled. Is it possible to export/consume this as a module? How? What are the benefits? ...
0 votes
0 answers
37 views
Use header-only (+implementation .h files) across multiple files in C++ project [duplicate]
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 ...
1 vote
1 answer
820 views
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/...
0 votes
1 answer
434 views
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 ...
5 votes
3 answers
1k views
using `[[gnu::noinline]]` in header-only library
Functions in a header-only library should be declared as inline to prevent multiple definitions in the different translation units. That is, for example, I wrote a header-only library mylib.hpp: void ...
1 vote
0 answers
593 views
Can I reduce the compile-time of my header-only library with a separate translation unit?
I am looking for a way to reduce compile-time for header-only libraries. If there are only headers, each translation unit must compile all functions it needs, hence there is a lot of duplicate work ...