Answer the question
In order to leave comments, you need to log in
What in CMAKE should I consider a library?
I have a C++ project with the following structure:
include/
lib/
src/
src
I put all the CPP
files. But I also needed the tinyfiledialogslib/
, and in main.cpp
I connected it like this#include "../lib/tinyfiledialogs/tinyfiledialogs.h"
g++
I just need to add this library to the command arguments.g++ src/main.cpp lib/tinyfiledialogs/tinyfiledialogs.h
add_library()
. In what cases should I use it and should I use it in this case? Maybe just put all the files in add_executable()
?
Answer the question
In order to leave comments, you need to log in
In general, libraries are usually installed separately into the system (for Linux) using a standard package manager.
If your library is not in the package manager, then you can build from source.
In this case, you can just "put" all the files in add_executable. Nobody can stop you from doing this.
But it's usually easier, better, and more versatile for third-party libraries to create their own targets with add_library and link them to the main target with target_link_libraries. The library can be made both dynamic and static.
If the project is quite spread out and contains, for example, tests and / or several executable files, then in general it is possible to create a separate static library in each project directory. On large projects, this can often save compilation time, due to the fact that ready-made libraries will be linked to several final targets, and not rebuilt from source each time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question