I’m working on an older project under RHEL 7 with GCC 4.8.5. I have cmake3 3.17.5 installed.
I’m building a shared library that is complaining about a for loop error:
error: ‘for’ loop initial declarations are only allowed in C99 mode
for (size_t i = 0;
in the libraries CMakeLists, I’m setting:
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)
I see the following is being set:
MakeFiles/3.17.5/CMakeCXXCompiler.cmake:set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "98")
I also have the following compiler flags set:
set(CPPFLAGS "-g -O2 -fPIC -pthread -DNET_LOG_MSG -fno-strict-aliasing -Wall -Wextra -Wno-unused -Wno-strict-aliasing -Werror=format-security -D_FORTIFY_SOURCE=2")
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPPFLAGS} ")
set(CMAKE_CXX_FLAGS_DEBUG "-U_FORTIFY_SOURCE -O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CPPFLAGS} -Wstrict-prototypes")
set(CMAKE_C_FLAGS_DEBUG "-U_FORTIFY_SOURCE -O0 -g")
set(CMAKE_C_FLAGS_RELEASE "-O3")
I’m sure I’m missing something here, but in other similar projects, I have essentially the same thing which has worked for quite some time. Admittedly, I haven’t been working much under el7, mostly under el8, where this code compiles fine. Of course the computed default there is 14.
Any help is greatly appreciated!
EDIT: This was a .c file so I needed CMAKE_C_STANDARD set.