'Solaris 8's gcc isn't searching for header files on NetBSD

I have a gcc 2.95.1 binary installed on a Solaris 8 VM. For an experiment, I'm trying to get it working in a NetBSD environment. However, I can't run the compilation phase on any program that involves #include directives, as the binary doesn't seem to be looking for libraries even without the -I flag specified. The example that I'm trying to test out now is a simple Hello World:

#include <stdio.h>
#include <stdlib.h>
int main() {
    printf("Hello World!\n");
    exit(0);
}

Running gcc -I some_random_directory -v -o hello_world.o -c hello_world.c on the Solaris 8 machine produced this:

Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.1/specs
gcc version 2.95.1 19990816 (release)
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.1/cpp -lang-c -v -I some_random_directory -D__GNUC__=2 -D__GNUC_MINOR__=95 -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem(unix) -Asystem(svr4) -D__GCC_NEW_VARARGS__ -Acpu(sparc) -Amachine(sparc) hello_world.c /var/tmp/ccA6aEZ8.i
GNU CPP version 2.95.1 19990816 (release) (sparc)
#include "..." search starts here:
#include <...> search starts here:
 some_random_directory
 /usr/local/include
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.1/../../../../sparc-sun-solaris2.8/include
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.1/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.1/../../../../include/g++-3
End of omitted list.
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.1/cc1 /var/tmp/ccA6aEZ8.i -quiet -dumpbase hello_world.c -version -o /var/tmp/ccUTCLhe.s
GNU C version 2.95.1 19990816 (release) (sparc-sun-solaris2.8) compiled by GNU C version 2.95.1 19990816 (release).

Running the same compilation command using the Solaris 8 gcc on NetBSD produced this:

Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.1/specs
gcc version 2.95.1 19990816 (release)
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.1/cpp -lang-c -v -I some_random_directory -D__GNUC__=2 -D__GNUC_MINOR__=95 -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem(unix) -Asystem(svr4) -D__GCC_NEW_VARARGS__ -Acpu(sparc) -Amachine(sparc) hello_world.c /var/tmp/ccFedUPd.i
GNU CPP version 2.95.1 19990816 (release) (sparc)
#include "..." search starts here:
#include <...> search starts here:
 .
 .
 .
 .
 .
End of search list.
The following default directories have been omitted from the search path:
 /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.1/../../../../include/g++-3
End of omitted list.
hello_world.c:1: stdio.h: No such file or directory
hello_world.c:2: stdlib.h: No such file or directory

At first, I thought gcc was just ignoring the -I flag, but the other search locations aren't showing up in the second output either. What might be going on here?



Solution 1:[1]

Even if you succeed with a compilation, it is unlikely that the toolchain will produce usable executables. However, to address the original question...

You need to override the compiler's idea of system include and library paths. To do this, you use -nostdinc, -isystem, -isysroot and --sysroot command line options.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 peteru