c++ - 英特尔编译器使用“属性“__malloc__”不接受参数的 C++14 检查失败
问题描述
我有以下代码(旨在检测编译器是否支持 C++14):
#include <memory>
#include <algorithm>
// Check the version language macro, but skip MSVC because
// MSVC reports 199711 even in MSVC 2017.
#if __cplusplus < 201402L && !defined(_MSC_VER) && !defined(__INTEL_COMPILER)
#error "insufficient support for C++14"
#endif
int main()
{
auto ptr = std::make_unique<int>(42);
constexpr int max = std::max(0, 1);
(void) ptr;
(void) max;
return 0;
}
使用g++
(版本 11.2.1)编译它时,g++ -std=c++14 test.cpp -o test
它工作正常。当使用 intel 编译器(版本 2021.3.0(gcc 版本 11.2.1 兼容性))而不是使用 编译它时icpc -std=c++14 test.cpp -o test
,它会失败并显示
In file included from /usr/include/c++/11/cwchar(44),
from /usr/include/c++/11/bits/postypes.h(40),
from /usr/include/c++/11/iosfwd(40),
from /usr/include/c++/11/bits/shared_ptr.h(52),
from /usr/include/c++/11/memory(77),
from test.cpp(1):
/usr/include/wchar.h(155): error: attribute "__malloc__" does not take arguments
__attribute_malloc__ __attr_dealloc_free;
^
In file included from /usr/include/c++/11/cstdlib(75),
from /usr/include/c++/11/bits/stl_algo.h(59),
from /usr/include/c++/11/algorithm(62),
from test.cpp(2):
/usr/include/stdlib.h(565): error: attribute "__malloc__" does not take arguments
__attr_dealloc_free;
^
In file included from /usr/include/c++/11/cstdlib(75),
from /usr/include/c++/11/bits/stl_algo.h(59),
from /usr/include/c++/11/algorithm(62),
from test.cpp(2):
/usr/include/stdlib.h(569): error: attribute "__malloc__" does not take arguments
__THROW __attr_dealloc (reallocarray, 1);
^
In file included from /usr/include/c++/11/cstdlib(75),
from /usr/include/c++/11/bits/stl_algo.h(59),
from /usr/include/c++/11/algorithm(62),
from test.cpp(2):
/usr/include/stdlib.h(797): error: attribute "__malloc__" does not take arguments
__attr_dealloc_free __wur;
^
compilation aborted for test.cpp (code 2)
这里到底出了什么问题,我该如何解决?
简短更新:看起来 CUDA 遇到了类似的问题,并且可能与 glibc 2.34 有关:https ://forums.developer.nvidia.com/t/cuda-11-5-samples-throw-multiple-error-属性-malloc-does-not-take-arguments/192750/15
解决方案
使用 icpc 2021.4 编译和执行共享代码,运行良好。
使用下面的命令来编译代码。icpc -std=c++14
下面是环境细节。
操作系统:Ubuntu 18.04.3 LTS 内核:Linux 4.15.0-76-generic
有关兼容性,请参阅英特尔® C++ 编译器经典系统要求的链接
推荐阅读
- xpages - Xpages onClick 执行顺序
- google-bigquery - Bigquery 计划查询创建导致错误
- mysql - GROUP BY 与 OVER
- c# - EF Core:在 PostgreSQL 中处理 nullable
- ruby-on-rails - 如何在 Rails 中正确实现达到配额的功能
- python - PyWavelet 中 MATLAB 的 cwtft2 的模拟?
- angular - 将 id 添加到 Angular 组件的 url,以便用户可以在浏览器中使用“返回”
- moodle - core_user_create_user 和 moodle 网络服务设置不工作
- python - how to configure logging system in one file on python
- python - discrepancy between gradients and trained parameters calculated internally with the model.fit and using tape.gradient and applying them manually