Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have a program that compiles with no problems on my Raspberry Pi using
gcc
that includes the statement:
#include <sys/socket.h>
My intent for this project, though, is to use it on an Arduino. I have installed avr-gcc, avr-LibC, and avrdude, but when I try to compile using:
avr-gcc Project.c -o Project
I receive the error message:
fatal error: sys/socket.h: No such file or directory
I thought socket.h
was part of the C standard library. Is it possible to install this library for use by avr-gcc, or is there a way I can point to this library's directory (I have been unable to find it myself in the usual folders, but GCC seems to be able to find it)?
–
–
Can avr-gcc use sys/socket.h?
No. It cannot. That's not a limitation of the compiler though. It's a limitation of the system your code needs to be run on.
The sys/*.h
headers are not part of the C standard library. They are only available on POSIX compliant operating systems, and expose C functions to interact with the OS. The sys/socket.h
header provides functions to communicate with the operating system to create, manipulate and interact with sockets.
Since sockets are a feature provided by the operating system, and you are compiling code that runs bare-metal on an Arduino microcontroller, which has no operating system running on top, the whole purpose of the sys/socket.h
header is nullified.
This applies to any other kind of header or library function that interacts with the operating system, such as unistd.h
, fcntl.h
, pthread.h
etc. In fact, avr-libc
, the Standard C library for AVR-GCC, does not provide such headers.
You will need to look at the avr-libc
documentation to find out more about the headers and functions that are provided and their usage.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.