简体   繁体   English

如何将C ++ 14标准要求从基于POCO的项目更改为C ++ 17

[英]How to change C++14 standard requirement from POCO based project to C++17

I am building a project using Cmake and POCO, I am using vcpkg to manage my dependencies in ubuntu so at first this is how my cmake file looks like 我正在使用Cmake和POCO构建项目,正在使用vcpkg在ubuntu中管理我的依赖项,因此首先这就是我的cmake文件的外观

cmake_minimum_required(VERSION 3.8)
project(web)
set(CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Poco COMPONENTS Net Util PDF SQL XML REQUIRED)
add_executable(web "main.cpp")
target_link_libraries(web PRIVATE Poco::Net Poco::PDF Poco::SQL 
Poco::XML)

but then I found out this is what is going on at the commandline 但是后来我发现这是命令行中发生的事情

 /usr/bin/g++-7  -DPOCO_ENABLE_CPP14 -DPOCO_HAVE_FD_EPOLL - 
 DPOCO_STATIC -DPOCO_UNBUNDLED -D_DEBUG -D_FILE_OFFSET_BITS=64 - 
 D_LARGEFILE64_SOURCE -D_REENTRANT -D_THREAD_SAFE - 
 D_XOPEN_SOURCE=500 -isystem /home/pius/vcpkg/installed/x64- 
 linux/include -g   -std=gnu++17 -std=gnu++14 -MD -MT 
 CMakeFiles/web.dir/main.cpp.o -MF CMakeFiles/web.dir/main.cpp.o.d - 
 o

as you can POCO is adding a new definition -DPOCO_ENABLE_CPP14 and it is passing -std=gnu++14 to gcc by default since my code depends on C++17 string_view I want C++17, I have tried to edit my CMake file to look like this -DPOCO_ENABLE_CPP14 ,POCO正在添加新定义-DPOCO_ENABLE_CPP14并且默认情况下它将-std=gnu++14传递给gcc,因为我的代码取决于C ++ 17 string_view我想要C ++ 17,所以我尝试编辑CMake文件看起来像这样

cmake_minimum_required(VERSION 3.8)
project(web)
find_package(Poco COMPONENTS Net Util PDF SQL XML REQUIRED)
add_executable(web "main.cpp")
set(CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-std=gnu++17)
remove_definitions(-DPOCO_ENABLE_CPP14 -std=gnu++14)
target_link_libraries(web PRIVATE Poco::Net Poco::PDF Poco::SQL 
Poco::XML)

but still Cmake is still generating the same effect as before, the remove_definitions command is not working, is there anyway I can over write the default requirement imposed by POCO and use my own instead? 但是Cmake仍会产生与以前相同的效果,remove_definitions命令不起作用,无论如何,我是否可以重写POCO施加的默认要求并改用我自己的默认要求? thanks 谢谢

我终于找到了一个解决方案,事实证明我可能无法决定依赖项,但是我可以通过以下方式决定自己的项目

set_target_properties(web PROPERTIES CXX_STANDARD 17)

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

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