【发布时间】:2019-06-02 18:49:52
【问题描述】:
根据此处的讨论,我已将reported a bug 发送给 Ubuntu 开发人员。
在编译以下示例 c++ 程序时:
#include <cmath>
#include <stdio.h>
int main()
{
printf("%f\n", std::cosf(0.0f));
}
我收到以下错误消息:error: ‘cosf’ is not a member of ‘std’
包括math.h 并使用非命名空间版本可以正常工作。怎么回事?
我在 Ubuntu 19.04 上使用 g++ 8.3.0-6ubuntu1。
我正在使用g++ --std=c++17 test.cpp 构建
【问题讨论】:
-
你的编译命令是什么?只是一个光秃秃的
g++ main.cpp? -
我认为
std::sinf、std::cosf等是在 C++11 中添加的。您是否在启用 C++11 的情况下进行编译? -
g++ --std=c++17 main.cpp
-
在 Godbolt 上,使用 g++ 或 clang 与 libstdc++ 时会出错。它在使用 clang -stdlib=libc++ 时有效。
-
@Shawn C++17 要求它在那里,所以这个库比标准落后了几年。