Mo's Blog

POC with CMake libraries

When exploring C++ libraries and making POCs external libraries can be a hassle. Especially if your distribution's package manager doesn't include them or only outdated versions. On the other hand, I don't want to clutter the system's filesystem with make && make install to test some functionality quickly.

One solution is to install the library in a temporary folder in your home directory and manually include and link it. For this, I first build and install the external library:

wget https://example.com/libexample.tar.gz
tar -xzvf libexample.tar.gz
cd libexample
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=$HOME/tmp-libexample ..
make
make install

Then, I can run something like the following command to compile my POC with that library:

clang -lstdc++ -std=c++23 \
    -o poc -I$HOME/tmp-libexample/include \
    poc.cpp $HOME/lib64/libexample.a

As I'm linking this library without CMake, I might need to add other libraries (e.g., -lm), so I set an appropriate C++ standard as in the example.