Qt 5.7 adding -std = gnu ++ 11 to my compiler flags, clobbering -std = C ++ 14

I set the following flags in CMakeLists.txt

 set(CMAKE_CXX_FLAGS "-std=c++14 -g -O0") 

Then I use find_package to find Qt5Test

 find_package(Qt5Test REQUIRED) 

Then I create a Model Test

 add_library (modeltest STATIC ${SRCS}) target_link_libraries(modeltest Qt5::Test) 

For some reason, I get -fPIC -std=gnu++11 to my compiler flags

 CMakeFiles/modeltest.dir/flags.make:CXX_FLAGS = -std=c++14 -g -O0 -fPIC -std=gnu++11 

This is clobbering my flag -std=c++14 , as a result of which all C ++ 14 functions in my program end up as compiler errors:

 error: 'foo' function uses 'auto' type specifier without trailing return type constexpr auto foo() ^ note: deduced return type only available with -std=c++14 or -std=gnu++14 
  • Is there any way to fix this?
  • I am using the latest version of Qt 5.7, downloaded from their site today.
+5
source share
1 answer

Do not explicitly set CMAKE_CXX_FLAGS .
Use this instead:

 set(CMAKE_CXX_STANDARD 14) 

This will determine the standard that will be used for each purpose.


As indicated in the comments, the following should also be considered:

 set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) 

See this link for more details.
Thanks to @CraigScott for pointing this out.


As mentioned in @wasthishelpful's comments, the CXX_STANDARD, CXX_STANDARD , and CXX_EXTENSIONS can also be used for each target configuration.
See the links above for more details.

+11
source

Source: https://habr.com/ru/post/1260311/


All Articles