It's the first time I encounter this error.
I am trying to clone openvr and get the hello opengl sample running, following their instructions:
cd samples
mkdir build
cd build
cmake .. -G "Visual Studio 14 2015 Win64" -DCMAKE_PREFIX_PATH=C:/Qt/5.6/msvc2013_64/lib/cmake
I get:
$ cmake .. -G "Visual Studio 14 2015 Win64" -DCMAKE_PREFIX_PATH=C:/Qt/5.6/msvc20 13_64/lib/cmake
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler using: Visual Studio 14 2015 Win64
-- Check for working C compiler using: Visual Studio 14 2015 Win64 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 14 2015 Win64
-- Check for working CXX compiler using: Visual Studio 14 2015 Win64 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Compilation set for 64bits architectures.
CMake Warning at CMakeLists.txt:40 (message):
SDL x64 runtime binaries not provided on Windows.
CMake Error at CMakeLists.txt:98 (message):
Unsupported compiler.
-- Configuring incomplete, errors occurred!
See also "C:/Users/GBarbieri/Documents/Visual Studio 2015/Projects/openvr/sample s/build/CMakeFiles/CMakeOutput.log".
If I go to check line 98:
if( (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang"))
# Better to use the prebuilt GNU preprocessor define __GNUC__,
# kept for legacy reason with the sample code.
add_definitions(-DGNUC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -include ${SHARED_SRC_DIR}/compat.h")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -pedantic -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
# Handles x86 compilation support on x64 arch.
if(${PLATFORM} MATCHES 32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
endif()
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Za")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /w2 /DEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MP /INCREMENTAL:NO")
else()
message(FATAL_ERROR "Unsupported compiler. ") // line 98
endif()
It seems it couldn't match "MSVC".. let me do a try, let me add before this snippet of code:
message("${CMAKE_CXX_COMPILER_ID}")
if(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
message("match")
else()
message("!match")
endif()
And then it returns:
MSVC
!match
CMake Error at CMakeLists.txt:104 (message):
Unsupported compiler.
What?
Can you spot what is wrong, guys?
Ok, as I've tried in the comment, the right answer is to use:
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
instead of
if(${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
Related
I've got MSVS 2022 and clang llvm installed on win10, I'm using vscode and cmake(version 3.23.2). On powershell command line I have a directory containing several cpp files and a CMakeLists.txt, then:
mkdir build
cd build
cmake -D CMAKE_TOOLCHAIN_FILE="..\cmaketoolchain.win10clang" ..
The content of cmaketoolchain.win10clang is as below:
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
SET (CMAKE_C_COMPILER "d:\\Program Files\\LLVM\\bin\\clang.exe")
SET (CMAKE_C_FLAGS "-Wall -std=c99")
SET (CMAKE_C_FLAGS_DEBUG "-g")
SET (CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_C_FLAGS_RELEASE "-O4 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
SET (CMAKE_CXX_COMPILER "d:\\Program Files\\LLVM\\bin\\clang++.exe")
SET (CMAKE_CXX_FLAGS "-Wall")
SET (CMAKE_CXX_FLAGS_DEBUG "-g")
SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
Well, on running cmake it still prints:
cmake -D CMAKE_TOOLCHAIN_FILE="..\cmaketoolchain.win10clang" ..
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043.
-- The C compiler identification is MSVC 19.31.31104.0
-- The CXX compiler identification is MSVC 19.31.31104.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: d:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
...
And generate a bunch of vcproj files.
Did I miss anything about cmake or environmental setting? How to solve it?
I'm on win10 and I have installed: MSVS2022 with msc++ compiler, codeblocks with Mingwin-g++ compiler and then llvm clang.
I then installed latest cmake and have a very simple CMakeLists.txt in a directory named basic with some cc files:
cmake_minimum_required(VERSION 2.8)
project(my)
add_executable(my main.cc power.cc)
I do these commands in powershell:
mkdir build
cd build
cmake ../basic.
-- Building for: Visual Studio 17 2022
CMake Deprecation Warning at CMakeLists.txt:17 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
-- The C compiler identification is MSVC 19.31.31104.0
-- The CXX compiler identification is MSVC 19.31.31104.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: d:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/H
But I wish I could use g++ or clang++, so I tried several methods at the same time.
(1) I changed CMakeLists.txt to add some lines:
set(CMAKE_C_COMPILER "clang")
set(CMAKE_CXX_COMPILER "clang++")
SET (CMAKE_C_COMPILER "d:\\Program Files\\LLVM\\bin\\clang.exe")
SET (CMAKE_C_FLAGS "-Wall -std=c99")
SET (CMAKE_C_FLAGS_DEBUG "-g")
SET (CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_C_FLAGS_RELEASE "-O4 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
SET (CMAKE_CXX_COMPILER "d:\\Program Files\\LLVM\\bin\\clang++.exe")
SET (CMAKE_CXX_FLAGS "-Wall")
SET (CMAKE_CXX_FLAGS_DEBUG "-g")
SET (CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE "-O4 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
cmake_minimum_required(VERSION 2.8)
project(my)
add_executable(my main.cc power.cc)
I cleaned the directory under build and run cmake again. Doesn't work, still choose msvc compiler.
Then I set environmental variable in Powershell like this:
$env:CC="d:\Program Files\LLVM\bin\clang.exe"
$env:CXX="d:\Program Files\LLVM\bin\clang++.exe"
I tried again. Doesn' work. Then I used the command line option:
cmake ..\basic\ -DCMAKE_CXX_COMPILER="d:\Program Files\LLVM\bin\clang++.exe"
Doesn't work. All methods tried together, still chooses msvc.
How to solve this problem?
Trying to build samples/mqtt/basic_pub_sub sample from aws-iot-device-sdk-cpp-v2 which contains CMakeList.txt:
cmake_minimum_required(VERSION 3.1)
# note: cxx-17 requires cmake 3.8, cxx-20 requires cmake 3.12
project(basic-pub-sub CXX)
file(GLOB SRC_FILES
"*.cpp"
)
add_executable(${PROJECT_NAME} ${SRC_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD 14)
#set warnings
if (MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX /wd4068)
else ()
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wno-long-long -pedantic -Werror)
endif ()
find_package(aws-crt-cpp REQUIRED)
target_link_libraries(${PROJECT_NAME} AWS::aws-crt-cpp)
Trying to build:
mkdir build
cd build
cmake ..
Got errro:
-- The CXX compiler identification is GNU 9.3.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:21 (find_package):
By not providing "Findaws-crt-cpp.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"aws-crt-cpp", but CMake did not find one.
Could not find a package configuration file provided by "aws-crt-cpp" with
any of the following names:
aws-crt-cppConfig.cmake
aws-crt-cpp-config.cmake
Add the installation prefix of "aws-crt-cpp" to CMAKE_PREFIX_PATH or set
"aws-crt-cpp_DIR" to a directory containing one of the above files. If
"aws-crt-cpp" provides a separate development package or SDK, be sure it
has been installed.
-- Configuring incomplete, errors occurred!
I found aws-crt-cpp-config.cmake if folder home\a\cpp_projects\sdk-cpp-workspace\lib\aws-crt-cpp\cmake
But how to tell about it to CMake?
I try to get clang 5.0.0 working for Visual Studio 2015, because I need OpenMP 3.0 features. I installed the clang compiler (not the vs2015 version which does not have any openmp support) and use cmake:
cmake_minimum_required(VERSION 2.8.10)
project(myproject)
find_package(OpenMP)
if (OPENMP_FOUND)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
include_directories("include")
add_library(libFoo STATIC Foo.cpp)
install(TARGETS Foo libFoo LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
When I now try to configure a MSVC 14 2015 Win64 build with or without toolchain LLVM-vs2014 I always get an error, that OpenMP is not found:
The C compiler identification is Clang 5.0.0
The CXX compiler identification is Clang 5.0.0
Check for working C compiler: D:/Program Files/LLVM/msbuild-bin/cl.exe
Check for working C compiler: D:/Program Files/LLVM/msbuild-bin/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: D:/Program Files/LLVM/msbuild-bin/cl.exe
Check for working CXX compiler: D:/Program Files/LLVM/msbuild-bin/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) (found version "1.0")
Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) (found version "1.0")
Configuring done
The used compiler seems to be the right one (Installed clang, not the Microsoft version), it autodetects the clang-cl binary, but OpenMP fails.
I tried to manually specify the compilers with "specify native compilers" and get the same result. It even selects the clang-cl version instead of clang++.
Related Answer, which does not solve the problem:
Compiling C code with openmp using clang-cl - Recent clang has libomp.lib and libiomp5.dll included
It is really a bit tricky and the cmake autodetection doesn't seem to work very well. What helped is
OpenMP_CXX_FLAGS="-Xclang -fopenmp"
OpenMP_C_FLAGS="-Xclang -fopenmp"
And making sure that libomp.lib is in the link libraries.
-Xclang tells the clang binary, that the following options are in clang format and not in MSVC format and -fopenmp is then just the usual OpenMP flag. Setting it any other way did not work, though.
The general pattern is: -Xclang -clangFlag1 -Xclang -clangFlag2.... Namely each Clang Style flag requires its own -Xclang.
I am trying to setup cmake using Windows 10 using MinGW. I have included the path c:/MinGW/bin in my system path and environment path settings. I have removed sh.exe from my path (although, i would love to be able to keep this if possible).
CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
set(CMAKE_C_COMPILER "C:/MinGW/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/MinGW/bin/gcc.exe")
project (Tutorial)
add_executable(Tutorial tutorial.cpp)
Output
C:\School\athabascua\data structures\ass1>cmake -g "MinGW Makefiles" .
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_b3144\fast"
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.8/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/MinGW/bin/gcc.exe" is not able to compile a simple test
program.
It fails with the following output:
Change Dir: C:/School/athabascua/data structures/ass1/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_b3144\fast"
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO"
"cmTC_b3144\fast"
It seems that the GNU compilers are identified but don't seem to work. Any help would be much appreciated. I am trying to avoid using Cygwin.. but almost ready to go that route in a sec here.
To fix the problem I was having, I had to do two things.
use the command cmake -G "MinGW Makefiles" . (capital -G on windows)
update my CMakeLists.txt file to use gcc for C compiler and g++ for C++ compiler
CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
set(CMAKE_C_COMPILER "C:/MinGW/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/MinGW/bin/g++.exe")
project (Tutorial)
add_executable(Tutorial tutorial.cpp)