gcc 7.2.0无法识别std :: expf和std :: logf [英] std::expf and std::logf not recognized by gcc 7.2.0
问题描述
似乎gcc(尝试7.2.0和5.4.0)没有 std :: expf 和 std :: logf -请参阅coliru 样本。由于cppreference表示它们是在C ++ 11中添加的,我是否缺少某些gcc特定宏,或者它们在gcc中总体上还是缺失的?
It seems that gcc (tried 7.2.0 and 5.4.0) does not have std::expf and std::logf - see coliru sample. Since cppreference says they were added in C++11 is there some gcc specific macro I am missing or are they in general missing in gcc?
推荐答案
这是libstdc ++中的错误,该错误与GCC一起提供。它不完全符合C ++ 17( as于2019年6月的v9.1.0版本)。 Ubuntu默认使用的< cmath>
版本的版权声明说它的最新更新时间是2016年。版本9.1.0的确有 #if __cplusplus> 201402L
部分,但未声明C ++ 17所需的标识符。 有未解决的错误报告。
This is a bug in libstdc++, which ships with GCC. It does not fully conform to C++17 (as of v9.1.0 in June 2019). The copyright notice on the version of <cmath>
that Ubuntu uses by default says it was last updated in 2016. Version 9.1.0 does have a #if __cplusplus > 201402L
section, but it doesn’t declare the identifiers required by C++17. There is an open bug report.
它从不声明 expf
或 logf
(也不声明 cosf
, sinf
等),即使 C ++ 17表示应 C ++ 11 standard 说,在C中定义为函数的名称应在C ++标准库中定义为函数,标准C库中使用外部链接声明的每个名称都保留给实现,以用作在命名空间std
和全局命名空间中都具有外部 C
链接的名称。但是, std :: expf
等。从< cmath>
提供的功能表中丢失,直到 P0175r1在2016年6月。这显然是一个疏忽,但GCC始终只在全局命名空间中提供它们。
It never declares expf
or logf
(nor cosf
, sinf
, etc.) within the std::
namespace, even though C++17 says it shall. The C++11 standard says, "Names that are defined as functions in C shall be defined as functions in the C++ standard library," and "Each name from the Standard C library declared with external linkage is reserved to the implementation for use as a name with extern "C"
linkage, both in namespace std
and in the global namespace." However, std::expf
et al. are missing from the table of functions provided by <cmath>
until P0175r1 in June 2016. This was apparently an oversight, but GCC has always made them available only in the global namespace.
libc ++ 库确实声明了它们,因此可以使用 clang ++ -std = c ++ 17 -stdlib = libc ++
进行编译。您还可以 #include< math.h>
在全局名称空间中使用它们,或使用重载的 exp()
, log()
,等等。
The libc++ library does declare them, so compiling with clang++ -std=c++17 -stdlib=libc++
should work. You can also #include <math.h>
to use them in the global namespace, or use the overloaded exp()
, log()
, etc. on float arguments.
这篇关于gcc 7.2.0无法识别std :: expf和std :: logf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!