1
votes

I have this old C++ project I'm compiling. It wasn't written by me. I'm attempting to compile it for someone I know. The code dates way back to the early 1990s, late 1980s, though some of it was still developed circa 2008 or so. Although I see Visual Studio 2013 was used. I'm attempting to compile it in VS 2015. Long story short, I'm getting an error where the "vector" is included. In vector "cmath" is included and that's where the errors crop up. Apparently this code was successfully compiled in earlier versions of Visual Studio, i.e. 2013 or 2010.

This is a large project, so it's hard to present this fully, but here is the top of the source file where vector is included:

#ifndef EXPRESSAPPLICATION_H
#define EXPRESSAPPLICATION_H

#pragma warning (disable : 4786)

#include <windows.h>
#include <vector>
#include "ObjList.h"

Here is the error list:

Severity Code Description Project File Line Suppression State

Error C2062 type 'double' unexpected ExpressOffice C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath 17

Error C2059 syntax error: ')' ExpressOffice C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath 17

Error C2143 syntax error: missing ';' before '{' ExpressOffice C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath 18

Error C2447 '{': missing function header (old-style formal list?) ExpressOffice C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath 18

Error C2062 type 'float' unexpected ExpressOffice C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath 30

Error C2059 syntax error: ')' ExpressOffice C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath 30

Error C2143 syntax error: missing ';' before '{' ExpressOffice C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath 31 Error C2447 '{': missing function header (old-style formal list?) ExpressOffice C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath 31

Error C2062 type 'long double' unexpected ExpressOffice C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath 328

Error C2059 syntax error: ')' ExpressOffice C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath 328

Error C2143 syntax error: missing ';' before '{' ExpressOffice C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath 329

Error C2447 '{': missing function header (old-style formal list?) ExpressOffice C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cmath 329

Here are the lines of code it's complaining about in cmath:

line 17:
_Check_return_ inline double abs(_In_ double _Xx) _NOEXCEPT
    {
    return (_CSTD fabs(_Xx));
    }

line 30:
_Check_return_ inline float abs(_In_ float _Xx) _NOEXCEPT
    {
    return (_CSTD fabsf(_Xx));
    }

line 328:
_Check_return_ inline long double abs(_In_ long double _Xx) _NOEXCEPT
    {
    return (_CSTD fabsl(_Xx));
    }

It appears that only the abs() functions in cmath are affected. None of the other math functions are affected. I'm mystified by this problem. Thanks for any help on this!

1
Change abs to std::abs and fabs to std::fabs.Jesper Juhl
Perhaps windows.h defines a macro for abs. You could insert something like #ifdef abs #undef abs #endif after including windows.h (in separate lines, of course).chtz
@chtz If that's the reason, possibly swapping the two includes, i.e. putting #include <vector> before #include <windows.h>, might help without manual undefs?CiaPan
Cannot duplicate with either VS 2015 or 2019, so the problem is somewhere else in the code not posted.dxiv

1 Answers

0
votes

I got these same errors, and found out the cause was because I had

#include <math.h>

in a couple of source files, but I also had

#include <cmath>

in another source file. I changed the <cmath> to <math.h> and it fixed the problem.