I have a C/C++ project that is built using CMake. While trying to compile a static binary, I've run into issues with different GLIBC
versions on my computer and the target machine. In a different question on SO, the accepted answer to a similar problem is to use an alternative implementation of the libc, like musl
or uClibc
. (See here)
I can't find any information on how to point cmake
to using such an alternative libc. Neither is a FindMusl.cmake
file shipped, nor can I find one on the internet. Simply using CC=/usr/bin/musl-gcc
does not work.
How can I link my cmake project statically against such alternative libc implementations, making it independent from GLIBC?
To use musl library with cmake, use something like this:
export CC="musl-gcc"
cmake -DCMAKE_EXE_LINKER_FLAGS="-static -Os" ..
make
or
export CC="musl-gcc"
cmake -DCMAKE_C_FLAGS="-static -Os" ..
make
or
export CC="musl-gcc -static -Os"
cmake ..
make
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With