简体   繁体   English

Windows + VS2019 + CMake + CLion + Conan:如何启用 C++20?

[英]Windows + VS2019 + CMake + CLion + Conan: How to enable C++20?

I'm getting this error:我收到此错误:

C:.conan\\7c4aa5\\1\\include\\absl/meta/type_traits.h(622): error C2039: 'result_of': is not a member of 'std' C:.conan\\7c4aa5\\1\\include\\absl/meta/type_traits.h(622): error C2039: 'result_of': 不是'std'的成员

When trying to compile my project which includes Abseil .尝试编译包含Abseil 的项目时。

If I click into where the error is coming from, I see:如果我点击进入错误的来源,我会看到:

#if __cplusplus >= 201703L
// std::result_of is deprecated (C++17) or removed (C++20)
template<typename> struct result_of;
template<typename F, typename... Args>
struct result_of<F(Args...)> : std::invoke_result<F, Args...> {};
#else
template<typename F> using result_of = std::result_of<F>;
#endif

And right there at the top is a hint, that std::result_of was removed in C++20.就在顶部是一个提示, std::result_of在 C++20 中被删除了。

In my CMakeLists.txt I have在我的CMakeLists.txt我有

set(CMAKE_CXX_STANDARD 20)

So why isn't __cplusplus >= 201703L true?那么为什么__cplusplus >= 201703L不是真的? What sets that variable?是什么设置了那个变量? How do I tell the compiler I really do want to use C++20?我如何告诉编译器我真的想使用 C++20?

I don't know if I need to convince Visual Studio 16/2019, or CMake, or CLion, or what.我不知道我是否需要说服 Visual Studio 16/2019,或者 CMake,或者 CLion,或者什么。 There's too many things in the toolchain, but I shall add some screenshots so you can see what my setup is and hopefully someone can point out what I'm missing.工具链中的东西太多了,但我会添加一些屏幕截图,这样您就可以看到我的设置是什么,希望有人能指出我遗漏了什么。

在此处输入图片说明

在此处输入图片说明

My full CMakeLists.txt is:我的完整CMakeLists.txt是:

cmake_minimum_required(VERSION 3.21)
set(EXE mario4ever)
project(${EXE})

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(${CMAKE_CURRENT_SOURCE_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${EXE} src/bootstrap.cpp)

target_link_libraries(${EXE} ${CONAN_LIBS})

add_custom_command(
        TARGET ${EXE} POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_directory
        ${CMAKE_SOURCE_DIR}/resources $<TARGET_FILE_DIR:${EXE}>/resources
        COMMENT "Copying shaders" VERBATIM
)

I just got it to compile.我刚刚得到它来编译。 The magic line was this:神奇的线是这样的:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++20 /Zc:__cplusplus")

Add that to CMakeLists.txt .将其添加到CMakeLists.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM