我试图构建一个集成OR-Tools的项目,使用Qt Creator中的MSCV 2019,但有奇怪的构建错误(目前在Abseil源代码中有数百个,但可能只是因为它是先构建的):
C:\我的项目\建设_部门\absl-src\absl\时间\时间.h:110:错误:C2039:'ratio':不是'std'的成员
C:\程序文件(x86)\Microsoft Visual Studio \2019\社区\VC\工具\MSVC\14.29.30133\包含\算法(40):注意:请参阅'std'的宣告
C:\我的项目\建设_部门\absl-src\absl\时间\时间.h:110:错误:C2061:语法错误:标识符'比率'
408:我的项目是什么?408:错误:C2760:语法错误:未预期的词语基元'{',必须是')'
我使用FetchContent
获取OR-Tools,并使用下面的CMakeLists.txt
(我已经删除了大部分默认的Qt样板文件):
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})
有关信息,Qt Creator将依次调用:
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
第一个失败的编译命令是:
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
我错过了什么吗?
2条答案
按热度按时间fkvaft9z1#
你能用c17代替c20试试吗?
jjhzyzn02#
当一个项目(如https://github.com/abseil/abseil-cpp,由or-tools使用)有一个名为
time.h
的文件时,就会发生这种情况。该项目在独立构建时构建良好,但当在定义set(CMAKE_INCLUDE_CURRENT_DIR ON)
的顶级项目中与FetchContent
一起使用时,<ctime>
最终会包含项目中的time.h
文件,而不是系统中的time.h
文件。我用