Skip to content
Advertisement

Building C with automake under OS X and Linux

Currently I’m writing a RPC system for delay tolerant networks based on the Serval project from Australia (GitHub) in C.

Mainly I’m developing on macOS El Capitan and everything works fine. But it is somewhat important that my code runs on macOS and Linux. But Linux makes trouble.

I choose automake as my build system since this is the only one I have at least a little experience. I also tried CMake, but with little success.

My problem is now that everything works nice on macOS. But on Linux (Debian) nothing compiles. autoreconf produces a configure script without errors, configure produces a Makefile without errors. But make yields a lot errors. And if I say a lot I really mean a lot (about 75.000 lines).

The first issue is the following: In file included from /usr/include/x86_64-linux-gnu/sys/types.h:29:0, from /usr/local/include/curl/curlbuild.h:131, from /usr/local/include/curl/curl.h:34, from rpc.h:1, from main.c:1: /usr/include/x86_64-linux-gnu/bits/types.h:30:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘typedef’ typedef unsigned char __u_char;

I googled around and found some people saying that this type of error comes somewhere from the user code, maybe a missing ; or similar. But I double-checked everything. And a missing ; would also be a problem on macOS, too.

My code can be found in my Github repo. Please use the dev branch. At this point the repo is somewhat disgusting and not clean at all. I will clean up when everything is running.

Thank you for your help 🙂

Advertisement

Answer

This is because of serval/general/features.h. Here how it goes:

curl/curl.h gets to include curlbuild.h, which includes sys/types.h.

sys/types.h includes features.h (expecting the one coming from glibc), which includes sys/cdefs.h, which define __BEGIN_CDECL (to nothing, since this is C, not C++.)

sys/types.h starts with (snipping around the stuff that is not required)

__BEGIN_CDECL

typedef unsigned char __u_char;

since __BEGIN_CDECL is not defined, it errors out.

Avoid using -Iserval/general in your command line and include the file with the full relative path, and it should be alright.

Advertisement