I'm trying to port our build system from make
to CMake
, and I encountered a problem that surprisingly not "Googleable"
Our code is C++ 11/14, compiles fine with GCC6.2, the make
applies zillion switches when invoking GCC, mostly pedantic warnings. I built a CMake
system that compiles (GCC 6.3) most of the code without a problem but some modules failed to build because of the following
flexible array member ‘blahblah’ not at end of ‘struct‘
Aside why it appears in the C++ code. Why did it compile in the make
based system? AFAIK, flexible array is not a part of C++ standard. GCC specific extension? What command line switch controls FAM behavior? How do I make it compile as it did in the original make
system?
In case someone needs a snippet of compiled code
struct Foo
{
int _10;
double _20;
int a[];
};
struct Bar
{
Foo foo;
double _1;
int _2;
}
To add more context, the cmake
file
cmake_minimum_required(VERSION 3.9)
project(foo VERSION ${FOO_VERSION} DESCRIPTION "foo")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_STANDARD 99)
add_executable(foo foo.cpp foo_backup.cpp main.cpp)
set_target_properties(foo PROPERTIES VERSION ${PROJECT_VERSION})
target_include_directories(foo PUBLIC ${CMAKE_SOURCE_DIR}/lib/include ${CMAKE_SOURCE_DIR}/lib/include/bar)
How do I make it compile as it did in the original make system
Revert to GCC 6.2. This -pedantic
error was introduced for C++ in GCC 6.3.
See compilation with 6.2 and compilation with 6.3
Disabling pedantic compilation will remove the error but entail other relaxations.