0

I have an installation of DPDK and I'm trying to compile code with it. This worked on my WSL machine, however on the test server, with the same install of dpdk, I'm getting the error:

/usr/local/include/rte_mempool.h: error: unknown type name 'ssize_t'

I've noticed this header does not include /sys/types.h, but it also doesn't include that on the machine that this works on. I don't know where it's supposed to come from, but it's coming from somewhere.

How do I get these headers to be aware of ssize_t?


As noted in a comment:

The compiler options include -std=c99 -O3 -march=native -I/usr/local/include -include rte_config.h, and a whole bunch of -l options (dpdk's make structure adds these in). This prompted me to run gcc --version and the working one is Ubuntu gcc 9.3.0 and the broken one is gcc 5.4.0. Seems like it might be an incompatibility between dpdk and the gcc installed.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Brydon Gibson
  • 1,179
  • 3
  • 11
  • 22
  • Have you tried `#include `? But note that, although `ssize_t` is *standard* C++, it isn't (IIRC) standard in C. – Adrian Mole Jul 26 '21 at 13:59
  • https://stackoverflow.com/questions/55190317/where-is-ssize-t-defined-in-linux – larsks Jul 26 '21 at 14:00
  • @AdrianMole The confusion is coming from the fact that I shouldn't have to modify DPDK's installed header files, _especially_ because this works on a different machine. I'm concerned this has something to do with my installation – Brydon Gibson Jul 26 '21 at 14:13
  • @BrydonGibson: In which case we would be guessing. – Joshua Jul 26 '21 at 14:23
  • @Joshua How are these headers _supposed_ to be aware of these types, if they aren't included in the header themselves? From there I can figure out what might differ between installations – Brydon Gibson Jul 26 '21 at 14:25
  • 3
    `ssize_t` is defined in `sys/types.h` which is typically hauled in automatically by `#include ` – Joshua Jul 26 '21 at 14:26
  • 1
    What compilation options are you using (is the package using)? You might need to actively request the POSIX data types such as `ssize_t` by an appropriate `#define` (e.g. `#define _XOPEN_SOURCE 700` or `-D_XOPEN_SOURCE=700` in the command-line options. – Jonathan Leffler Jul 26 '21 at 14:50
  • 1
    @JonathanLeffler `-std=c99 -O3 -march=native -I/usr/local/include -include rte_config.h`, and a whole bunch of -l options (dpdk's make structure adds these in). This prompted me to run `gcc --version` and the working one is ubuntu gcc 9.3.0 and the broken one is gcc 5.4.0. Seems like it might be an incompatibility between dpdk and the gcc installed – Brydon Gibson Jul 26 '21 at 15:35
  • 1
    The `-std=c99` option suppresses the POSIX features unless you add `-D_XOPEN_SOURCE=700` or equivalent — which explains why you are now running into problems (but not why it worked somewhere else). Use `-std=gnu99` to get the definitions without needing to specify `_XOPEN_SOURCE`. – Jonathan Leffler Jul 26 '21 at 15:37
  • 1
    See also [GCC with `-std=c99` complains about not knowing `struct timespec`](https://stackoverflow.com/q/3875197/15168). This question is effectively a duplicate of that one — the type name is different, but the cause of the trouble is the same. It would be helpful if you put the compiler options into the question so it is clearer to those coming later what causes the trouble. – Jonathan Leffler Jul 26 '21 at 15:58

1 Answers1

2

As mentioned in the comments by @JonathanLeffier, the root cause of the issue is including sys/types.h when gcc option --std=c99 is passed. The easiest fix without modifying the DPDK or sample code is to include the path to types.h as part of cflags.

If the native build is for x86_64 target, follow these steps:

  1. execute find /usr/include/ -name types.h to identify the right file for local build (this is because the current cflags has -march=native)
  2. modify the CFLAGS from -std=c99 -O3 -march=native -I/usr/local/include -include rte_config.h to -std=c99 -O3 -march=native -I/usr/local/include -include rte_config.h --include=/usr/include/[target-machine]/sys/types.h

Note: In my humble suggestion please use pkg-config for populating the right CFLAGS and LDFLAGS for both shared and static binary.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Vipin Varghese
  • 4,540
  • 2
  • 9
  • 25