'Can't build OR-Tools (fetched with FetchContent) with MSVC in Qt Creator
I'm trying to build a project that integrates OR-Tools, with MSCV 2019 in Qt Creator, but there are strange build errors (hundred of them, in Abseil source code at the moment, but probably only because it's built first):
C:\MyProject\build_deps\absl-src\absl\time\time.h:110: erreur : C2039: 'ratio': is not a member of 'std'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\algorithm(40): note: see declaration of 'std'
C:\MyProject\build_deps\absl-src\absl\time\time.h:110: erreur : C2061: syntax error: identifier 'ratio'
C:\MyProject\build_deps\absl-src\absl\time\time.h:408: erreur : C2760: syntax error: unexpected token '{', expected ')'
I'm fetching OR-Tools with FetchContent, with the following CMakeLists.txt (I've removed most of the default Qt boilerplate):
cmake_minimum_required(VERSION 3.15)
project(MyProject VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools)
set(PROJECT_SOURCES main.cpp)
qt_add_executable(${PROJECT_NAME}
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
include(FetchContent)
set(BUILD_DEPS ON)
set(BUILD_SAMPLES OFF)
set(BUILD_EXAMPLES OFF)
FetchContent_Declare(
or-tools
GIT_REPOSITORY https://github.com/google/or-tools.git
GIT_TAG v9.3
)
FetchContent_MakeAvailable(or-tools)
target_link_libraries(${PROJECT_NAME} PRIVATE or-tools)
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
target_compile_options(${PROJECT_NAME} PRIVATE /experimental:external /external:anglebrackets /external:W0)
qt_finalize_executable(${PROJECT_NAME})
For information, Qt Creator successively calls:
C:\Qt\Tools\CMake_64\bin\cmake.exe -S "C:/MyProject" -B "C:/MyProject/build" "-DCMAKE_GENERATOR:STRING=Ninja" "-DCMAKE_BUILD_TYPE:STRING=Debug" "-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=C:/Qt/Tools/QtCreator/share/qtcreator/package-manager/auto-setup.cmake" "-DQT_QMAKE_EXECUTABLE:FILEPATH=C:/Qt/6.3.0/msvc2019_64/bin/qmake.exe" "-DCMAKE_PREFIX_PATH:PATH=C:/Qt/6.3.0/msvc2019_64" "-DCMAKE_C_COMPILER:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe"
C:\Qt\Tools\CMake_64\bin\cmake.exe --build "C:/MyProject/build" --target all
The first failed compile command is:
C:\MSVC\x64\cl.exe /nologo /TP
-I"C:\MyProject\build\_deps\absl-build\absl\time"
-I"C:\MyProject\build\_deps\absl-src\absl\time"
-I"C:\MyProject\build\_deps\absl-build\absl\time\time_zone_autogen\include"
-I"C:\MyProject\build\_deps\absl-src"
/DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd /W3 /DNOMINMAX
/DWIN32_LEAN_AND_MEAN /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS /D_ENABLE_EXTENDED_ALIGNED_STORAGE
/bigobj /wd4005 /wd4068 /wd4180 /wd4244 /wd4267 /wd4503 /wd4800 -std:c++20 /showIncludes
/Fo_deps\absl-build\absl\time\CMakeFiles\time_zone.dir\internal\cctz\src\time_zone_lookup.cc.obj
/Fd_deps\absl-build\absl\time\CMakeFiles\time_zone.dir\time_zone.pdb
/FS -c "C:\MyProject\build\_deps\absl-src\absl\time\internal\cctz\src\time_zone_lookup.cc
Am I missing something?
Solution 1:[1]
Can you try with c++17 instead of c++20?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Laurent Perron |

