Erlang RunTime System have a few integrated drivers written in C to do some interaction with the OS or access to some low level resources for example : handle networking like creating sockets and listen or accepting uncoming connections is done by the driver
As my knowledge, these drivers are compiled and loaded by the ERTS at boot time.
I wanted to create a driver and test it, and as the Erlang Manual said : after coding a driver you need to compile it with C Language OS compiler and load it from Erlang code and finally link to it by a spawned process so it’s very simple and clear.
I tried to do these steps using a pre-existed driver :
inet_drv.c so I search for it’s location and tried to compile it using Clang Compiler in FreeBSD System :
cc inet_drv. c.
cc is the Clang’s command to compile a C program, the compilation said that the file
erl_driver.h is not defined because the driver code include this header file, so I searched for it and add the path to it’s directory using
-I option in
cc command, and after compilation there was be another header file not defined. I continued to search and add paths to the compiler until all headers files directories are added to the
cc command, the command was :
cc inet_drv.c -I/usr/ports/lang/erlang/work/otp-OTP-22.214.171.124/erts/emulator/beam -I/usr/local/lib/erlang/usr/include -I/usr/ports/lang/erlang/work/otp-OTP-126.96.36.199/erts/emulator/sys/unix -I/usr/ports/lang/erlang/work/otp-OTP-188.8.131.52/erts/include/internal -I/usr/ports/lang/erlang/work/otp-OTP-184.108.40.206/erts/emulator/sys/common -I/usr/local/lib/erlang/erts-11.0/include/internal ```
After that, I was surprised by 7 warnings and 13 errors generated, the shell output and errors and warnings description are in links below, so what is happening here ?
Since this driver works perfectly in response to Erlang networking tasks, why it returns errors when compile it ?
In other terms, what the ERTS do to run these drivers ?
As I mentioned before, the Manual said that you should compile the driver, load it from Erlang code and link to it by an Erlang process, so the ERTS should compile the driver in first using an OS C Language Compiler and add included headers that the driver needs exactly like I did or I missed something ?