pixelpress
pixelpress

Reputation: 119

Build error "ISO C++ forbids zero-size array ‘f_handle’ [-Wpedantic]" only when using snapcraft VM

I'm using the catkin command line tools to build benchmark_catkin, which is a catkin wrapper for Google's benchmark. The build uses a CMakeLists file and always worked fine so far on Ubuntu 18.04. I'm now trying to build this package with snapcraft. Snapcraft has the catkin-tools plugin and sets up a VM before building. However, I'm now getting an error from a system library and the build is not successful:

In file included from /root/parts/workspace/install/usr/include/x86_64-linux-gnu/bits/fcntl.h:61:0,
                 from /root/parts/workspace/install/usr/include/fcntl.h:35,
                 from /root/parts/workspace/build/benchmark_catkin/benchmark_src-prefix/src/benchmark_src/src/sysinfo.cc:23:
/root/parts/workspace/install/usr/include/x86_64-linux-gnu/bits/fcntl-linux.h:355:27: error: ISO C++ forbids zero-size array ‘f_handle’ [-Wpedantic]
   unsigned char f_handle[0];
                           ^
In file included from /root/parts/workspace/install/usr/include/x86_64-linux-gnu/bits/fcntl.h:61:0,
                 from /root/parts/workspace/install/usr/include/fcntl.h:35,
                 from /root/parts/workspace/build/benchmark_catkin/benchmark_src-prefix/src/benchmark_src/src/timers.cc:23:
/root/parts/workspace/install/usr/include/x86_64-linux-gnu/bits/fcntl-linux.h:355:27: error: ISO C++ forbids zero-size array ‘f_handle’ [-Wpedantic]
   unsigned char f_handle[0];
                           ^
make[5]: *** [src/CMakeFiles/benchmark.dir/sysinfo.cc.o] Error 1
make[5]: *** Waiting for unfinished jobs....
make[5]: *** [src/CMakeFiles/benchmark.dir/timers.cc.o] Error 1
make[4]: *** [src/CMakeFiles/benchmark.dir/all] Error 2
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [all] Error 2
make[2]: *** [benchmark_src-prefix/src/benchmark_src-stamp/benchmark_src-build] Error 2
make[1]: *** [CMakeFiles/benchmark_src.dir/all] Error 2
make: *** [all] Error 2

I assume this error is referring to a zero-size array in the libc6-dev library. Since I'm using base: core18 in my snapcraft.yaml and also running an Ubuntu 18.04 system, I'm wondering why I just get the error in the VM. Is this a bug in the library? How can I solve this?


For reference, my snapcraft.yaml file:

name: nav 
base: core18 
version: 'w1.0'
summary: The Nav Software  
description: |

grade: devel  
confinement: strict 

plugs:   
  network:
  network-bind:

parts: 

  core-dep:
    plugin: nil
    build-packages:
      - autoconf
      - libtool
      - git

  workspace:
    plugin: catkin-tools
    source: .
    catkin-packages: [catkin_simple, glog_catkin, gflags_catkin, benchmark_catkin]
    after: [core-dep]

On request, here the code around the erroneous line of /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h:

/* File handle structure.  */
struct file_handle
{
  unsigned int handle_bytes;
  int handle_type;
  /* File identifier.  */
  unsigned char f_handle[0];
};

Upvotes: 0

Views: 839

Answers (1)

eerorika
eerorika

Reputation: 238441

I took a look into the project. CMakeLists.txt of benchmark_catkin internally checks out google/benchmark and builds that. The error comes from that build.

CMakeLists.txt google/benchmark sets tons of compiler options, and specifically -pedantic-errors (as well as -pedantic and -Werror) which causes the compiler to stop on any use of a language extension. Frankly in my opinion, CMakeLists.txt should not set any warning flags and especially no -Werror or -pedantic-errors flags without the user asking for it, so I would consider that a bug, but google devs may disagree.

The glibc header uses a language extension. But that is fine because warnings in system headers should be ignored. So the actual cause for the build failure is failure to treat the glibc header as a system header.

I know nothing about snapcraft, but I suspect that the cause of the problem is in there.

Upvotes: 2

Related Questions