Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Target requires the language dialect "CXX17" (with compiler extensions), but CMake does not know the compile flags to use to enable it

Tags:

c++

c++17

cmake

So I've been trying to include the <filesystem> into my project, which seem to be a bigger problem than I thought. <filesystem> should be part of c++17, I need to add that definition into my CMakeList.

My root CmakeLists look like this:

MESSAGE(“In src CMAKELIST”)

#
# Build everything in include/ directory
add_subdirectory(include)
#

#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

## Main executable target
add_executable(cmakeDemo main.cpp)

# These libraries get built in include/*/, CMake will auto-set required
# compiler flags and include paths from their definitions
target_link_libraries(cmakeDemo record ${portaudio})
target_link_libraries(cmakeDemo database)
target_link_libraries(cmakeDemo match)
target_link_libraries(cmakeDemo spectogram)

In which I added the c++17 definition, but when I compile my system, I get this error:

 make 
“InsrcCMAKELIST”
“InincludeCMAKELIST”
“IndatabaseCMAKELIST”
“InmatchCMAKELIST”
“InrecordCMAKELIST”
“InspectogramCMAKELIST”
/home/lamda/soundcloud/src/include/spectogram/base/base.h
“outspectogramCMAKELIST”
-- Configuring done
CMake Error in src/CMakeLists.txt:
  Target "cmakeDemo" requires the language dialect "CXX17" (with compiler
  extensions), but CMake does not know the compile flags to use to enable it.


-- Generating done
-- Build files have been written to: /home/lamda/soundcloud/build
make: *** [cmake_check_build_system] Error 1

But somehow isn't it willing to use c++17, so I can use the filesystem library? why?

like image 689
Lamda Avatar asked Nov 11 '17 13:11

Lamda


2 Answers

Update about gcc

Building our own GCC from the sources is actually a bad idea...

In my case I get some errors by trying to link with an external library (even made with the same c++ standart /GCC version)

The best practice seems to use devtoolset yum package instead https://www.softwarecollections.org/en/scls/rhscl/devtoolset-7/

It seems that this package has been made by including some Redhat patches an configure switch for you. So as far we don't known the magic recipe to make it work properly, it make sens to use something more official.

Conlusion: use devtoolset yum package instead or trying to compile GCC from sources

like image 113
chtimi59 Avatar answered Nov 19 '22 19:11

chtimi59


As mentioned is c++17 only supported by cmake version > 3.8, so I had to update it.

But my problem was my gcc and g++ didn't support it, so I had to update those, which I then did.

I followed this guide.

like image 18
Lamda Avatar answered Nov 19 '22 20:11

Lamda