I followed this 'tutorial' to create a static GCC, libc, and libstdc++ built against MUSL.
Build directory: /home/user/musl_gcc/
When I attempt to create a simple test C program, and compile it with no arguments, I get the following error:
[user@Arch]: ~/musl_gcc/amd64-linux-musl/bin>$ cat test.c
#include <stdio.h>
#include <unistd.h>
int main()
{
puts("Test");
_exit(0); // return 0 leads to a segfault (unsure why)
}
[user@Arch]: ~/musl_gcc/amd64-linux-musl/bin>$ ./amd64-linux-musl-gcc test.c
collect2: fatal error: cannot find 'ld'
compilation terminated.
[user@Arch]: ~/musl_gcc/amd64-linux-musl/bin>$ which ld
/usr/bin/ld
[user@Arch]: ~/musl_gcc/amd64-linux-musl/bin>$ `!!` -v
`which ld` -v
GNU ld (GNU Binutils) 2.29.1
The linker does NOT point to the custom built one, nor would I expect it to.
This can be rather easily circumvented by compiling and linking in separate steps:
[user@Arch]: ~/musl_gcc/amd64-linux-musl/bin>$ ./amd64-linux-musl-gcc test.c -c
[user@Arch]: ~/musl_gcc/amd64-linux-musl/bin>$ ./amd64-linux-musl-ld test.o -L../lib/ -lc -o test
./amd64-linux-musl-ld: warning: cannot find entry symbol _start; defaulting to 00000000004000e8
[user@Arch]: ~/musl_gcc/amd64-linux-musl/bin>$ ./test
Test
[user@Arch]: ~/musl_gcc/amd64-linux-musl/bin>$
However. this is of little use to me. I'd eventually like to get it to work with C++ applications that use CMake as a build environment, but this has been a tedious cat-and-mouse game of "find the library." How do I specify the linker to use? I thought it was though the LD
environment variable, but that proved fruitless.