3

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.

Goodies
  • 4,439
  • 3
  • 31
  • 57
  • related: https://stackoverflow.com/questions/1867745/cmake-use-a-custom-linker – Jean-François Fabre Dec 19 '17 at 22:41
  • That might be all I need. – Goodies Dec 19 '17 at 22:42
  • "The linker does NOT point to the custom built one, nor would I expect it to" -- why would you not expect that? I account your toolchain broken if the gcc driver does not know how to find and run the appropriate component parts. – John Bollinger Dec 19 '17 at 22:46
  • Well, it simply says "cannot find 'ld'" but when I perform `which ld`, it doesn't show the path to the custom linker. I wouldn't expect it to because, well, it's not called `ld`. – Goodies Dec 19 '17 at 22:50
  • But the point is, why would you not expect your cross-compiling compiler driver to know the correct name and location of your cross-compiling linker? Perhaps that indeed *is* what you should expect, but I would have thought that these are among the things that you can configure at build time. Clearly the expected location, at least, is among those things, since the compiler does not pick up the (wrong) linker from your path. – John Bollinger Dec 19 '17 at 23:19
  • @JohnBollinger when I read 1 `I followed this 'tutorial'` I know that is much too early for this person to do such an advanced things. – 0___________ Dec 19 '17 at 23:27
  • Well, not necessarily @PeterJ_01. Unnecessary condescension aside, I'm capable of understanding at least most of what's going on here. The script he provided is incredibly intuitive and, while I don't have a lot of experience with cross compilation, I'm still vaguely familiar with the compilation/linking processes. – Goodies Dec 20 '17 at 00:48
  • @Goodies I afraid I am right. The correct way is know how everything works and then doing something like this. There is nothing wrong in using tutorials but always IMO knowledge is the must. – 0___________ Dec 20 '17 at 00:51
  • I understand that. I've built GCC from source before and have not had these issues. But again, I've little experience with cross-compilation, hence my question on SO. – Goodies Dec 20 '17 at 00:56
  • 1
    @PeterJ_01, tutorial aside, the reason I raise the issue at all is to prompt the OP to look for an appropriate configuration setting among GCC's build options. I don't know whether there actually is one, but I see reason to hope. If the OP were not competent to look for such a thing himself, then that would be a different issue, but I see reason for hope on that front as well. – John Bollinger Dec 20 '17 at 13:39

0 Answers0