I’m building the benchmark_catkin package with catkin. This is a wrapper which loads a version of Google benchmark. Building worked fine so far on my “local” system. However, when I use snapcraft, it gives me the -Wpedantic error:
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];
The error is pretty clear. Is there an option to be less strict with this ISO C++ standard? I’m wondering why the VM builds this code differently than my “local” catkin build command.
Edit: I can clearly find the reason for this error in the file /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h which is:
I agree, seems odd that you’re getting different behavior locally. I don’t see anything in the code that should be causing this, @sergiusens/@cjp256 any ideas? @prex, any chance you could share your snapcraft.yaml?
Do the compiler versions match? I assume your project has -Wpedantic conditionally defined, but the behavior may change with different compiler versions… can you see if that flag is being used for your local builds?
Perhaps you can try building it in an ubuntu 18:04 container and see if you get the same results?
gcc -v gives me version 7.5.0 in the VM and 7.4.0 on my “local” system.
In the benchmark_catkin wrapper, I couldn’t find any hint of -Wpedantic in the CMakeLists. In my local catkin config I’m not using any additional CMake Args.
Regarding the C++ version, I tried to add add_definitions(-std=c++11 -Wno-pedantic) to the CMakeLists but with the same result.
No, I’m really just trying to build the benchmark_catkin wrapper, which relies on the three other packages in the .rosinstall file. The Snapcraft.yaml should build like this.
Indeed, by removing these flags, it builds fine. However, forking both repos is not a really nice option and I would like to keep benchmark version 1.3.0 for the moment. I would prefer if snapcraft could handle the pedantic flags in the same way as my local system.
I’m not familiar with ros or catkin in particular. The main difference I can see is the weird paths for fcntl.h and friends in the initial error you reported:
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];
It seems to be including copies of these headers from within your Snapcraft project rather than the system ones in /usr/include. IIRC, the compiler treats certain “system header” directories as special w.r.t warning handling. That probably wouldn’t extend to the local copies of these headers.
So I guess the question is: why is there a copy of the system headers in your part’s install dir, and is it possible to avoid that?
@jamesh That’s my gut feeling as well. The plugin itself installs the build dependencies as staged packages, and those get used because snapcraft incorporates the staged includes.
I have created a simplified version of the plugin (ish) that does not reproduce this w/o using the staged resources, and it works fine.
Though I’m still not sure why the divergence in behavior. In my case, the staged headers/g++ match the host headers/g++…
When including system headers, they need to be included with -isystem. When used the pedantic warning/error will be suppressed.
We’ll have to sort out how best to fix this.
man g++
The -isystem and -idirafter options also mark the directory as a system directory, so that it gets the same special treatment that is applied to the standard system directories.
The header files declaring interfaces to the operating system and runtime libraries often cannot be written in strictly conforming C. Therefore, GCC gives code found in system headers special treatment. All warnings, other than those generated by ‘#warning’ (see Diagnostics), are suppressed while GCC is processing a system header.