Library design: allow user to decide between “header-only” and dynamically linked?

Preliminary note: I am assuming a Windows environment, but this should be easily transferable to other environments. Your library has to be prepared for four situations: Used as header-only library Used as static library Used as dynamic library (functions are imported) Built as dynamic library (functions are exported) So let’s make up four preprocessor defines … Read more

Quantifiable metrics (benchmarks) on the usage of header-only c++ libraries

Summary (notable points): Two packages benchmarked (one with 78 compilation units, one with 301 compilation units) Traditional Compiling (Multi Unit Compilation) resulted in a 7% faster application (in the 78 unit package); no change in application runtime in the 301 unit package. Both Traditional Compiling and Header-only benchmarks used the same amount of memory when … Read more

How do I create a header-only library?

You can use the inline keyword: // header.hpp (included into multiple translation units) void foo_bad() {} // multiple definitions, one in every translation unit 🙁 inline void foo_good() {} // ok 🙂 inline allows the linker to simply pick one definition and discard the rest. (As such, if those definitions don’t actually match, you get … Read more

CMake: target_include_directories() prints an error when I try to add the source directory itself, or one of its subdirectories

The origin of the problem is not the target_include_directories command itself, but the attempt to install a target that has a public or interface include directory prefixed in the source path (i.e. the include directory is a subdirectory of your ${PROJECT_SOURCE_DIR}.) While it is perfectly fine and desirable to use absolute paths when building the … Read more

In CLion, header only library: file “does not belong to any project target, code insight features might not work properly”

Little background I was having the same problem, albeit the project was not header-only, nevertheless, the open files from inc folder were throwing the aforementioned warning, even though the CMake file clearly marked that folder to be include_directory. *.hpp files do not belong to ${SOURCE} include_directories(“${PROJECT_SOURCE_DIR}/inc/”) add_subdirectory(src) add_executable(${EXECUTABLE_NAME} main.cpp ${SOURCE}) Since this is a perfectly … Read more

Benefits of header-only libraries

Benefits of header-only library: Simplifies the build process. You don’t need to build the library, and you don’t need to specify the compiled library during the link step of the build. If you do have a compiled library, you will probably want to build multiple versions of it: One compiled with debugging enabled, another with … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)