【问题标题】:why does it compile error when i only #include<math.h>为什么当我只有 #include<math.h> 时它会编译错误
【发布时间】:2020-03-21 03:30:48
【问题描述】:

我将gcc升级到5.4,除了math.h似乎还可以

当我写一个 hello.cpp 如下:

#include<math.h>
int main(){return 0;}

然后我用 gcc 5.4、g++ 5.4 编译上面的 cpp

g++ hello.cpp

发生错误

In file included from /usr/include/math.h:70:0,
                 from main.cpp:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:63:16: error: expected constructor, destructor, or type conversion before ‘(’ token
 __MATHCALL_VEC (cos,, (_Mdouble_ __x));
                ^
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:65:16: error: expected constructor, destructor, or type conversion before ‘(’ token
 __MATHCALL_VEC (sin,, (_Mdouble_ __x));
                ^
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:81:22: error: ‘sincos’ has not been declared
 __MATHDECL_VEC (void,sincos,,
                      ^
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:81:29: error: expected identifier before ‘,’ token
 __MATHDECL_VEC (void,sincos,,
                             ^
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:82:3: error: expected identifier before ‘(’ token

当我降级到 gcc 4.8、4.9 时,仍然会出现这个问题

【问题讨论】:

  • gcc 5.4 已经很老了。当前版本是 9.3。你能更新到更新的东西吗?您的 gcclibc6-dev 软件包都是最新的吗?
  • @KeithThompson gcc5.4 在我的其他服务中运行良好,我使用apt-get install gcc-5.4,然后使用apt-get install build-essential,所以 gcc 和 libc6-dev 是最新的
  • 我还尝试从 4.8、4.9 到 5.4 删除所有 gcc 和 g++ 版本和 apt-get install,但它没有帮助。我的意思是 gcc 在没有 #include 的情况下运行良好。所以我不知道该怎么办,是我在升级gcc时忘记安装的东西吗?
  • Google 搜索“mathcalls.h”“预期构造函数”表明其他人遇到了这个问题。在前几个结果中我没有看到解决方案。如果你的耐心超过我的耐心,也许你会找到一些东西。
  • @KeithThompson 所以一个可能的解决方案是重新安装我的系统?天哪,太糟糕了

标签: c++11 ubuntu-16.04 glibc gcc5


【解决方案1】:

这个问题对我来说是不可重复的。

g++ hello.cpp -ansi -Wall -pedantic

编译没有错误。并运行:

Valgrind 在运行时没有报告错误。

==100412== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

海报的安装有问题。另外,正如其他人所说,升级 gcc。

【讨论】:

  • 我不知道为什么需要这个,但是试试 -lm 标志。
  • 然后升级你的 Ubuntu 和 gcc。当有更新的系统可用时,我认为在过时的系统上花费资源没有多大意义?
  • 还是谢谢你,apt-get install linux-libc-dev 帮了我很多
【解决方案2】:

我找到了解决办法:

apt-get install linux-libc-dev

【讨论】:

  • 我有点怀疑那个特定的命令是什么解决了这个问题。 linux-libc-dev 是“用于开发的 Linux 内核头文件”。您的程序不执行任何应该依赖于内核头文件的操作。您在 cmets 中提到 apt-get upgrade 解决了问题,这似乎更合理。那可能会更新多个包,并且没有好的方法来判断哪个包真正解决了您的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-14
  • 2012-03-21
  • 1970-01-01
  • 2012-03-13
  • 1970-01-01
相关资源
最近更新 更多