Using an alternative libc in a cmake project
Asked Answered
M

2

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?

Methenamine answered 20/11, 2015 at 9:17 Comment(1)
Adjust the CFLAGS and the linker flags?! Maybe a duplicate of #2729052Protocol
O
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
Overrefinement answered 26/1, 2017 at 12:11 Comment(1)
not working: "Manually-specified variables were not used by the project"Euboea
E
0

This worked better for me:

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

source

Euboea answered 12/5, 2021 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.