My cmake file:
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_COMPILER "gcc-7")
project(invertedindex)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wconversion -O0")
set(SOURCE_FILES main.cpp inverted_index.hpp params.hpp)
add_executable(invertedindex ${SOURCE_FILES})
Fortunately I looked at the generated compiler command
/usr/local/bin/gcc-7 -Wall -Wextra -Wconversion -O0 -std=gnu++1z -o CMakeFiles/invertedindex.dir/main.cpp.o -c /Users/adam/school/cpp/invertedindex/main.cpp
and saw -std=gnu++1z
. I have no interest in studying long hours what the f*ck that is and why it is there when I have
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
It suspect that -std=gnu++1z is not a stable, finished library, or sth. But gcc 7 supports most of the features of c++17 standard.
when I chickened out of knowing that it should work, I replaced manually the generated command parameter to -std=gnu++17
and it worked. What's wrong? How do I make it work in cmake?
See how to specify compiler in cmake I was using the third method which is marked with avoid. First method, that is setting CXX
env var didn't work (compiler was some Mac g++). So I tried the second method - specifying compiler in cmake args -D CMAKE_C_COMPILER=gcc-7
, which worked. Even though generating again c++1z param. I don't understand it, but until I breaks I'm good.
/usr/local/bin/gcc-7 -Wall -Wextra -Wconversion -O0 -g -std=gnu++1z -o CMakeFiles/invertedindex.dir/main.cpp.o -c /Users/adam/school/cpp/invertedindex/main.cpp
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.