3 ms·
Generally you would use the operating system's package manager to install both the headers and the library. On distributions like Debian the library would be in
by Manfred 3y ago
Generally you would use the operating system's package manager to install both the headers and the library. On distributions like Debian the library would be in a package called `libsodium` and the headers in `libsodium-dev`.
Once the files are on the system, you use command-line switches to tell the compiler where to look for headers and which libraries to link to. Libraries are often loaded dynamically when the binary is started, so they are not actually included in the file.
Because maintaining the correct switches is a bit of a pain, there are tools like `pkg-config` to generate them for you. And there are tools like `autoconf` and `automake` to generate build scripts to orchestrate those tools.
In libraries it's pretty common for APIs to a library to be fairly stable, so the function signatures generally don't change very much in the headers. This is also why your application can be dynamically linked to different versions of a library.
There are obviously limitations and that's when people come into the equation. For example, OS distribution maintainers juggle these dependencies for you.
- 10000truths 3y agoFor package-manager-installed libraries in mainstream distros, you usually don't have to worry about the -I or -L flags, or deal with pkg-config, since the libraries are installed in places that are already under the compiler's default search paths. So the steps can be reduced to: 1. apt-get install libsodium libsodium-dev 2. #include "sodium.h" where needed 3. Add -lsodium flag to gcc/clang linking command