7

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?

Community
  • 1
  • 1
janoliver
  • 7,744
  • 14
  • 60
  • 103
  • Adjust the CFLAGS and the linker flags?! Maybe a duplicate of http://stackoverflow.com/questions/2728552/how-to-link-to-a-different-libc-file – usr1234567 Nov 20 '15 at 10:37

2 Answers2

3

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
0

This worked better for me:

 cmake -DCMAKE_TOOLCHAIN_FILE=${POLLY_ROOT}/gcc-static.cmake ..

source

eadmaster
  • 1,347
  • 13
  • 23