1

i upgrade gcc to 5.4, it seems to be ok except math.h

when i write a hello.cpp like the following:

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

then i compile the above cpp with gcc 5.4, g++ 5.4

g++ hello.cpp

errors happen

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

when i downgrade to gcc 4.8, 4.9, this problem still happens

wallace000
  • 21
  • 4
  • gcc 5.4 is pretty old. The current release is 9.3. Can you update to something newer? Are your `gcc` and `libc6-dev` packages both up to date? – Keith Thompson Mar 21 '20 at 03:39
  • @KeithThompson gcc5.4 run good in my other service, i use `apt-get install gcc-5.4`, and then `apt-get install build-essential`, so gcc and libc6-dev are up to date – wallace000 Mar 21 '20 at 04:10
  • i also try to remove all the gcc and g++ version and apt-get install from version 4.8, 4.9, to 5.4, but it doesnot help. i mean gcc runs good without #include like above . So i don't know what to do, it's there something i forget to install while upgrade gcc? – wallace000 Mar 21 '20 at 04:37
  • A Google search for "mathcalls.h" "expected constructor" indicates that others have run into this problem. I didn't see a solution in the first few results. Perhaps if your patience exceeds mine you'll find something. – Keith Thompson Mar 21 '20 at 05:09
  • @KeithThompson so a possible solution is to reinstall my system?, my god, it suck – wallace000 Mar 21 '20 at 05:29
  • I don't know. As I said, others have encountered the same problem, but I haven't been able to find a solution. Reinstallation *shouldn't* be necessary, but if Ubuntu 16.04 (which is also rather old, BTW) had this problem in general it never would have gone out the door. Have you dived into the Google search results I referred to? I'd try `sudo apt-get upgrade` (`man apt-get` first) to make sure all your packages are up to date. If you've been considering updating your system anyway (18.04 LTS is current, 20.04 LTS comes out in just a few weeks) this might be a good excuse. – Keith Thompson Mar 21 '20 at 08:56
  • See also https://askubuntu.com/q/865844 -- or you might consider clang. – Keith Thompson Mar 21 '20 at 08:56
  • @KeithThompson thank you guys, apt-get upgrade do help me a lot, – wallace000 Mar 22 '20 at 03:43
  • Does that mean it solved the problem? – Keith Thompson Mar 22 '20 at 04:06
  • yes @KeithThompson – wallace000 Mar 23 '20 at 10:03
  • If your problem is solved, you should accept an answer. (It's perfectly ok to accept your own answer.) But please see my comment on your answer and perhaps consider updating it. – Keith Thompson Mar 23 '20 at 21:05

2 Answers2

1

This question is not reproducuble for me.

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

Compiles without error. And runs:

Valgrind reports no errors upon running.

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

Something is wrong with the poster's installation. Also, as others have said, upgrade gcc.

user3236841
  • 1,088
  • 1
  • 15
  • 39
1

I found a solution:

apt-get install linux-libc-dev
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
wallace000
  • 21
  • 4
  • 1
    I'm a bit skeptical that that particular command was what solved the problem. `linux-libc-dev` is "Linux Kernel Headers for development". Your program does nothing that should depend on kernel headers. You mentioned in comments that `apt-get upgrade` was what solved the problem, which seems more plausible. That would probably have updated multiple packages, and there's no good way to tell which one actually solved your problem. – Keith Thompson Mar 23 '20 at 21:07