Erlang's default driver compiled with lot of errors

Hello everybody,

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 inet_drv.c.

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/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 ?

IMG-20211112-095309916-HDR — ImgBB
IMG-20211112-095339539-HDR — ImgBB
IMG-20211112-095355798-HDR — ImgBB
IMG-20211112-095431286-HDR — ImgBB


inet_drv.c may not be the best driver to look at to understand how drivers work. It it incredibly complicated and it is meant to be compiled in the Erlang/OTP source code tree. It is in no way a good example for writing your own driver.

That said, one thing that your command line misses is the inclusion of config.h. It is included like this:

To make sure that it actually gets included, you will need to add -DHAVE_CONFIG_H to your compilation command. You will also need to have access to the config.h file and make sure it can be found. It is generated when the configure command is run.


Thank you For your reply, I tried this driver because all massively systems that I know replace this driver for more scalability, so I thinked to be ready in the future that is, and I think you have right it’s very complicated and may be there is other things depends on command options in it’s code so compiling it should done by it’s writers whose Erlang’s Team


Also I have doubt in included files, when compilation said that a file is missed I search for this file but sometimes the search returns more than 1 directory so when I add one of these directories, It may contains other included files that share the same name with other files and they are no desired files


Can you point us to a good example driver? I’m tinkering with writing one at the moment. My lack of C experience is keeping progress at a “controlled” pace :grinning:


I was exactly like you, but C language is very easy to learn, I learned it in 1 week from “The C Programming Language” book, because anywhere you need C language and especially in parallel with Erlang and Beam


Last thing about that is that the default drivers of Erlang are statically loaded that means that a driver is compiled once when installing Erlang/OTP as part of it and linked to it, so the command to compile the driver and all others drivers is generated from “make” file, I can’t find Erlang/OTP “make” file source code for FreeBSD System but for Linux the line command for compiling inet_drv.c is very complicated and as @bjorng said there is “-DHAVE_CONFIG_H” which call an include to the header “config.h” that I didn’t include in my command line