Search code examples
cgcccross-compilingarm64

sys/socket.h is not found for gcc arm x86_64-aarch64 cross compiling


I'm trying to cross-compile(via gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf) a simple test.c

#include <sys/socket.h>
#include <stdio.h>
#include <unistd.h>

int main()
{
    int s = socket(AF_INET, 0, 0);
    printf("socket = %i\n", s);
    close(s);
}

with this command

/opt/gcc-arm-8.3-2019.03-x86_64-aarch64-elf/bin/aarch64-elf-gcc test.c -o test

But it fails with a message:

test.c:1:10: fatal error: sys/socket.h: No such file or directory

I even specified the /usr/include directory with -I flag but fails to find asm/socket.h

Same I tried directly from compiler executable directory (from /opt/gcc-arm-8.3-2019.03-x86_64-aarch64-elf/bin/) but ld fails to link literally any of the symbols in test.c.

Same was tested using gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf


Solution

  • As user253751 and Ian Abbott answered in comments, there are no header files because there is no operating system which defines "socket" entity.