2

I want to build xv6 on macOS, so I installed the cross-compiler toolchain i386-elf-gcc and i386-elf-gcc from a Homebrew Tap.

The problem is i386-elf-gcc cant link standard libraries while compiling. I tested on a simple c file, and got the following error.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
    printf("d\n");
    return 0;
}

Error:

> i386-elf-gcc --sysroot=usr/includes test.c
test.c:1:10: fatal error: stdio.h: No such file or directory
 #include <stdio.h>
          ^~~~~~~~~
compilation terminated.
Jay Wang
  • 2,650
  • 4
  • 25
  • 51
  • looks like a bad installation. (cross)Compilers are coming with the standard libraries and headers – Eugene Sh. Jan 31 '18 at 22:49
  • 1
    "problem is i386-elf-gcc cant link standard libraries" --> not quite. So far it is not a _linking_ problem, but the compiler is confused where the standard headers reside. – chux - Reinstate Monica Jan 31 '18 at 22:50
  • @EugeneSh. Do you think it might be caused by this [option](https://github.com/nativeos/homebrew-i386-elf-toolchain/blob/ec10b3a3848b8bc210ce25e5fd6d66057003a8a8/Formula/i386-elf-gcc.rb#L20) in the homebrew tap? – Jay Wang Jan 31 '18 at 22:52
  • @chux I added a `--sysroot=usr/includes` option to this gcc, but it doesn't really help. – Jay Wang Jan 31 '18 at 22:53
  • Have you actually used that option? – Eugene Sh. Jan 31 '18 at 22:53
  • @EugeneSh. It is on the Homebrew tap, so I guess homebrew uses this configuration to build i386-elf-gcc. – Jay Wang Jan 31 '18 at 22:54
  • 1
    Well. No. This option is telling not to use any of the target headers when *building* gcc. Can you locate the headers in the toolchain path? – Eugene Sh. Jan 31 '18 at 22:56
  • @EugeneSh. I found `/usr/local/Cellar/i386-elf-gcc/7.3.0/lib/gcc/i386-elf/7.3.0/include`, but I am not sure it is the right path? Interestingly there are `stdint.h`, `float.h`, but no `stdio.h`. – Jay Wang Jan 31 '18 at 23:10

1 Answers1

0

to resolve, you could try adding the newlib library and cross-compile it to your architecture. The following link says the freeware newlib can be used as source of the stdlib to compile all by yourself.

One problem is that the standard libraries provided with most software development tool suites arrive only in object form...

b.g.
  • 847
  • 8
  • 14