0

I am trying to compile an application and I have added these lines in CMakeLists.txt

option(DISPLAY "Display images and steps" OFF)
option(TESTS "Build tests too" OFF)

if (DISPLAY)
set(CMAKE_CXX_FLAGS "-g -Wall -std=gnu++11 -DDISPLAY_IMGS")
else()
set(CMAKE_CXX_FLAGS "-g -Wall -std=gnu++11")
endif()

(the lines are at the beginning of the file) I am getting an error like this:

In function ‘int main(int, char**)’:
error: in C++98 ‘featuresTypes’ must be initialized by constructor, not by ‘{...}’

Can anyone tell me why it is doing it? In fact building it in KDevelop works fine, but building it in terminal ($ cmake .. and $ make), it gives that error.


VERBOSE=1 says:

/usr/bin/cmake -H/home/xxx/proj/prj1 -B/home/xxx/proj/prj1/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/xxx/proj/prj1/build/CMakeFiles /home/xxx/proj/prj1/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/xxx/proj/prj1/build'
make -f CMakeFiles/prj1.dir/build.make CMakeFiles/prj1.dir/depend
make[2]: Entering directory `/home/xxx/proj/prj1/build'
cd /home/xxx/proj/prj1/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/xxx/proj/prj1 /home/xxx/proj/prj1 /home/xxx/proj/prj1/build /home/xxx/proj/prj1/build /home/xxx/proj/prj1/build/CMakeFiles/prj1.dir/DependInfo.cmake --color=
Dependee "/home/xxx/proj/prj1/build/CMakeFiles/optimisation.dir/DependInfo.cmake" is newer than depender "/home/xxx/proj/prj1/build/CMakeFiles/prj1.dir/depend.internal".
Dependee "/home/xxx/proj/prj1/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/xxx/proj/prj1/build/CMakeFiles/prj1.dir/depend.internal".
Scanning dependencies of target optimisation
make[2]: Leaving directory `/home/xxx/proj/prj1/build'
make -f CMakeFiles/optimisation.dir/build.make CMakeFiles/prj1.dir/build
make[2]: Entering directory `/home/xxx/proj/prj1/build'
/usr/bin/cmake -E cmake_progress_report /home/xxx/proj/prj1/build/CMakeFiles 1
[ 12%] Building CXX object CMakeFiles/prj1.dir/src/cpp/main.cpp.o
/usr/bin/c++    -I/usr/local/include/opencv -I/usr/local/include -I/home/xxx/proj/prj1/src/hpp    -o CMakeFiles/prj1.dir/src/cpp/main.cpp.o -c /home/xxx/proj/prj1/src/cpp/main.cpp
/home/xxx/proj/prj1/src/cpp/main.cpp: In function ‘int main(int, char**)’:
/home/xxx/proj/prj1/src/cpp/main.cpp:99:33: error: in C++98 ‘featuresTypes’ must be initialized by constructor, not by ‘{...}’

What it should do instead?

usr1234567
  • 21,601
  • 16
  • 108
  • 128
thedarkside ofthemoon
  • 2,251
  • 6
  • 31
  • 48

1 Answers1

2

Your flags aren't making into the build command at all. So either you tried to set these flags before the project line in your CMakeLists.txt, or you're including something afterwards that is overwriting them.

You should probably move them to after any project line and includes, and have them append to whatever the current value is, since last flag wins.

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -std=gnu++11")
if (DISPLAY)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDISPLAY_IMGS")
endif()
Mike DeSimone
  • 41,631
  • 10
  • 72
  • 96
  • yes, they should be after `project`... it seems to work now. In fact the problem had appeared after adding the `TESTS` option. I think it is some kind of `undefined behaviour` if you put the `flags` before `project` – thedarkside ofthemoon May 26 '14 at 14:29