1

I am trying to compile some source codes about UNIX scokets programs, on Linux I have no problems but on macOS I get stuck in front of types definition problems. I don't know how many details I can put here, but I'll try.

The source codes to be compiled are:

errlib.c
errlib.h
server_test.c
sockwrap.c
sockwrap.h

where the main is located in server_test.c.

To compile I use:

gcc -Wall -DTRACE -o server_test server_test.c errlib.c sockwrap.c

There are no problems running this on Linux, but on macOS I get more than 20 error and all of these are about a (perhaphs) missing definition of bool_t. I suppose something not working in /usr/include/rpc/* files located in macOS internal libraries.

So I looked for if <sys/types.h> is included in /usr/include/rpc/xdr.h and it seems to be not missing.

Some of the first lines of the gcc output are:

In file included from server_test.c:16:
/usr/include/rpc/xdr.h:126:3: error: type name requires a specifier or qualifier
                bool_t  (*x_getlong)(struct __rpc_xdr *, int *);
                ^
/usr/include/rpc/xdr.h:126:10: error: function cannot return function type 'int (struct __rpc_xdr *, int *)'
                bool_t  (*x_getlong)(struct __rpc_xdr *, int *);
                        ^
/usr/include/rpc/xdr.h:128:3: error: type name requires a specifier or qualifier
                bool_t  (*x_putlong)(struct __rpc_xdr *, const int *);
                ^
/usr/include/rpc/xdr.h:128:10: error: function cannot return function type 'int (struct __rpc_xdr *, const int *)'
                bool_t  (*x_putlong)(struct __rpc_xdr *, const int *);
                        ^

/usr/include/rpc/xdr.h:128:3: error: duplicate member 'bool_t'
                bool_t  (*x_putlong)(struct __rpc_xdr *, const int *);
                ^
/usr/include/rpc/xdr.h:126:3: note: previous declaration is here
                bool_t  (*x_getlong)(struct __rpc_xdr *, int *);
                ^
/usr/include/rpc/xdr.h:136:3: error: type name requires a specifier or qualifier
                bool_t  (*x_getbytes)(struct __rpc_xdr *, char *, unsigned int);
...

and many others lines that are very similar.

For those who want to deepen, the sources are available here.

What could be the problem?

shogitai
  • 1,823
  • 1
  • 23
  • 50

1 Answers1

1

The bad answer

Issue solved by simply including <rpc/types.h> in the server_test.c source as follows:

#include <rpc/types.h>

The better one

This is a solution above is valid only for this server_test.c implementation.

If you want fix this issue "globally", you can follow follown steps:

  • disable SIP (how to? here)

  • get your macOS's xdr.h (from here /usr/include/rpc/xdr.h)

  • copy it elsewhere two times: one copy is for backup and modify the other one simply adding the required include (#include <rpc/types.h> and see the picture below)

  • overwrite your modified xdr.h onto the original one in /usr/include/rpc/

  • re-enable SIP

Here is how I did it:

enter image description here

shogitai
  • 1,823
  • 1
  • 23
  • 50