cmath compilation error when compiling old C++ code in VS2010

吃可爱长大的小学妹 提交于 2019-11-29 14:08:21

问题


I've inherited a few C++ files and an accompanying makefile, which I'm trying to bring into VS2010 as a solution. I've created an empty project and added the appropriate C++ and header (.hpp) files for one of the makefile targets.

When I try to compile the project, however, I immediately get a large number of C2061 (syntax error identifier) errors coming from cmath regarding acosf, asinf, atanf, etc.

The error line in cmath:

#pragma once
#ifndef _CMATH_
#define _CMATH_
#include <yvals.h>

#ifdef _STD_USING
   #undef _STD_USING
     #include <math.h>
   #define _STD_USING

#else /* _STD_USING */
   #include <math.h>
#endif /* _STD_USING */

#if _GLOBAL_USING && !defined(RC_INVOKED)

_STD_BEGIN
using _CSTD acosf; using _CSTD asinf;

The top block of the relevant C++ file (though named as a .C):

#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

Followed by the main() function, which doesn't call any of the trig functions directly. This has to be something really obvious, but I'm missing it. Can anyone help?

Thanks!


回答1:


Are you sure it's compiling as C++? Most compilers will compile .C file as C and .cpp files as C++, compiling a C++ file with a C-compiler will probably fail.

Also, that code mixes oldstyle ('c') headers and newstyle ('c++') headers. It should be more like this (I doubt that is the error however).

#include <fstream>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

That's all I can see with what you've given. But most of the time when you get errors in library files of C/C++ itself, it still is code of you that's wrong somewhere, like forgetting the ; after a class statement in a header file.




回答2:


Its probably NOT compiling as C++ code - as you assume. I am going to ask you to right click on the file in vs2010, click properties, go to 'Configuration Properties - C/C++ - Advanced', and make sure 'Compile As' is set to 'Compile as C++ Code (/TP)'.. If not, change it to that, then recompile.. you may have to recreate your Pre-compiled Headers, but I am going to be this fixes your 'problem' ;)



来源:https://stackoverflow.com/questions/3141455/cmath-compilation-error-when-compiling-old-c-code-in-vs2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!