我正在使用一个名为PyPHS的Python库,专门用于物理建模。为了节省仿真过程中的计算量,实现了C++代码生成特性。它使用CMake生成特定仿真的可执行文件。
它在C++ 11中实现。
问题
在CMakeLists.txt文件中,C++ 11功能由以下行激活:
target_compile_features(<project_name> PUBLIC cxx_std_11)在我的计算机上(CMake 3.5.1 &Ubuntu16.04.4 Xenial Xerus),CMake抛出一个错误:这个特性是未知的:
-- The CXX compiler identification is GNU 5.4.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:31 (target_compile_features):
target_compile_features specified unknown feature "cxx_std_11" for target
"dampedosc".-配置不完整,出现错误!
另见"/home/victorw/git/vocal-phs/python/output/dampedosc/CMakeFiles/CMakeOutput.log".
在其他安装程序(Debian 8、Mac或windows 7)上没有遇到此错误。
Fix
我已经更改了CMakeLists.txt模板。下面是到提交的链接,在我自己的PyPHS叉上。
我把target_compile_features(<project_name> PUBLIC cxx_std_11)换成了set (CMAKE_CXX_STANDARD 11)
问题
这两个命令有什么区别?你对这件事有什么见解?我忘了提什么信息了吗?
谢谢你的回答!
发布于 2018-02-28 11:01:12
cxx_std_11编译器元特性在您的CMake版本中不可用.它是在3.8中引入的,因此这将解释错误,CMake 3.8发行说明。
两者的区别在于,target_compile_features()可以为特定的目标请求特定的特性。CMake将自动将适当的标准应用于指定的目标。另一方面,如果您设置了CMAKE_CXX_STANDARD,那么所请求的标准(如果得到CMake的支持)将应用于整个项目(针对所有目标)。
如前所述,CMake 3.8可以使用target_compile_features()请求整个标准,在这种情况下,与设置CMAKE_CXX_STANDARD的唯一区别是该标准仅应用于指定的目标(请参阅下面的内容)。
请注意,如果使用target_compile_features作用域调用PRIVATE,则请求的功能/标准将只将仅应用于指定的目标,如果设置了PUBLIC,则请求的功能/标准也将应用于依赖于该目标的任何目标。
https://stackoverflow.com/questions/49012222
复制相似问题