用C ++ 11激活 要么

问题描述 投票:1回答:1

我正在使用一个名为PyPHS的Python库,专门从事物理建模。为了在模拟期间保存计算,它实现了C ++代码生成功能。它使用CMake生成特定模拟的可执行文件。

它在C ++ 11中实现。


问题

在CMakeLists.txt文件中,C ++ 11功能由以下行激活:

target_compile_features(<project_name> PUBLIC cxx_std_11)

在我的计算机上(CMake 3.5.1和Ubuntu 16.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".
```

-- Configuring incomplete, errors occurred!
See also "/home/victorw/git/vocal-phs/python/output/dampedosc/CMakeFiles/CMakeOutput.log".

其他安装(Debian 8,Mac OSX或Windows 7)上未遇到此错误

固定

我已经更改了CMakeLists.txt模板。这是我自己的PyPHS分支上的提交链接。

我用target_compile_features(<project_name> PUBLIC cxx_std_11)取代了set (CMAKE_CXX_STANDARD 11)


这两个命令有什么区别?您对此事有何见解?我忘了提一些信息吗?

谢谢您的回答!

c++ c++11 cmake
1个回答
5
投票

cxx_std_11编译器元功能在您的CMake版本中不可用。它是在3.8中引入的,所以这可以解释错误,CMake 3.8 release notes

两者之间的区别在于target_compile_features()可以为特定目标请求特定功能。 CMake将自动将适当的标准应用于指定的目标。另一方面,如果您设置CMAKE_CXX_STANDARD,则所请求的标准(如果CMake支持)将在项目范围内应用(适用于所有目标)。

如上所述,你可以从CMake 3.8请求使用target_compile_features()的整个标准,在这种情况下,设置CMAKE_CXX_STANDARD的唯一区别是标准仅适用于指定的目标(如下所示)。

请注意,如果使用target_compile_features范围调用PRIVATE,则所请求的功能/标准将仅适用于指定的目标,如果设置了PUBLIC,则所请求的功能/标准也将应用于依赖于该目标的任何目标。

© www.soinside.com 2019 - 2024. All rights reserved.