C++11 为什么我只包含<;数学h>;

C++11 为什么我只包含<;数学h>;,c++11,ubuntu-16.04,glibc,gcc5,C++11,Ubuntu 16.04,Glibc,Gcc5,我把gcc升级到了5.4,除了数学,它似乎还可以 当我编写hello.cpp时,如下所示: #include<math.h> int main(){return 0;} 发生错误 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 c

我把gcc升级到了5.4,除了数学,它似乎还可以

当我编写hello.cpp时,如下所示:

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

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时,这个问题仍然存在

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

g++ hello.cpp -ansi -Wall -pedantic
编译时不会出错。并运行:

Valgrind在运行时不报告任何错误

==100412== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
海报的安装有问题。另外,正如其他人所说,升级gcc

我找到了一个解决方案:

apt-get install linux-libc-dev

gcc 5.4非常古老。目前的版本是9.3。你能更新到新的吗?您的
gcc
libc6 dev
软件包都是最新的吗?@KeithThompson gcc5.4在我的其他服务中运行良好,我使用
apt get install gcc-5.4
,然后
apt get install build sential
,因此,gcc和libc6开发人员都是最新的,我也尝试删除所有的gcc和g++版本,并将apt get install从4.8、4.9版删除到5.4版,但没有任何帮助。我的意思是,gcc运行良好,不包括上述内容。所以我不知道该怎么办,升级gcc时我忘记安装了什么?谷歌搜索“mathcalls.h”“expected constructor”表明其他人遇到了这个问题。在最初的几个结果中,我没有看到解决方案。也许如果你的耐心超过了我,你会发现一些东西。@KeithThompson那么一个可能的解决方案就是重新安装我的系统?天哪,太糟糕了。我不知道为什么需要这样做,但是试试-lm标志。并且升级你的Ubuntu和gcc。我不认为在更新的系统可用的情况下,在过时的系统上花费资源有多大意义?无论如何,谢谢你,apt get install linux libc dev帮我一个忙。我有点怀疑这个特定的命令是否解决了这个问题<代码>linux libc dev是“linux内核开发头”。您的程序不会执行任何依赖于内核头的操作。您在评论中提到,
apt get upgrade
解决了这个问题,这似乎更合理。这可能会更新多个包,并且没有好的方法来判断哪个包真正解决了您的问题。
apt-get install linux-libc-dev