I had a similar problem when compiling using -std=c++11 , but only in Debug : set(CMAKE_BUILD_TYPE Debug) mode set(CMAKE_BUILD_TYPE Debug) . In Release or RelWithDebInfo instead, everything works as expected.
I solved the problem of optimizing compiled code (in Debug mode) with the -O1 option. those. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O1") .
I do not understand why this works, but it works for me.
source share