Including Headers from C

Hello fellow people,

I want to include the C library socket.h in my Arduino program and am having trouble including the header.

#include <sys/socket.h>

works fine in typical C programming, but the Arduino IDE returns

No such file or directory

On the Mac, this directory is supposed to be in /usr/include/sys/socket.h, but on mine it wasn’t there. So I ssh’d into a Linux machine I have, found the directory, and copy/pasted it to network drive /Volumes/‘The Index’/P/Programming/Headers. The code

#include </Volumes/'The Index'/P/Programming/Headers/include/sys/socket.h>

returns the same error. I sensed my path was causing a problem, so I copied socket.h to my desktop and wrote

#include </Users/Eric/Desktop/socket.h>

which returns a different error:

In file included from /Volumes/The Index/B/Bionics Program/Haptic Interface/0.4/HapticInterface/HapticInterface.ino:2:0:
/Users/eric/Desktop/Headers/include/sys/socket.h:22:10: fatal error: features.h: No such file or directory
 #include <features.h>
          ^~~~~~~~~~~~
compilation terminated.
exit status 1
Error compiling for board Arduino Mega or Mega 2560.

I just want to use a standard C header on my Arduino. What am I doing wrong?

The Arduino IDE does not use standard library locations or arbitrary paths to libraries. The header file can be placed inside the sketch folder you are using

#include "socket.h"  // use quotes, not angle brackets

or else it will look in the libraries directory for a folder names "socket" which contains this header file.

blh64:
The Arduino IDE does not use standard library locations or arbitrary paths to libraries. The header file can be placed inside the sketch folder you are using

#include "socket.h"  // use quotes, not angle brackets

or else it will look in the libraries directory for a folder names “socket” which contains this header file.

This works for the individual header file - socket.h, but socket.h includes other libraries, each including libraries of their own. I would either need to include the entire C Headers file (5GB) or sift through each of these to see exactly what the dependencies are and include each of those in my Arduino project. Is there a better way?

You cannot use your computer's socket library on the Arduino. The Arduino doesn't have an operating system, there is no Linux kernel with a network stack that you can send your socket syscalls to.

You have to use the libraries that came with your Ethernet/WiFi shield.

Pieter

You may have to "roll your own" library that has the UNIX socket calls and "glues" them to the hardware you are using. Its not impossible. Just make sure you have a good reference and a lot of time.

Did this once years ago. Had to create a sockets library for the classic Mac toolbox so we could port UNIX code over to run on the Macs. Took bloody forever! Learned a lot though.

-jim lee