Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using an alternative libc in a cmake project

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?

like image 333
janoliver Avatar asked Nov 20 '15 09:11

janoliver


1 Answers

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
like image 135
jeffdlskafjdslfkjsd Avatar answered Oct 04 '22 13:10

jeffdlskafjdslfkjsd