本文介绍了在VS2010中编译旧的C ++代码时,cmath编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经继承了几个C ++文件和一个随附的makefile,我试图把它作为VS2010的解决方案。我创建了一个空项目,并为其中一个makefile目标添加了适当的C ++和头文件(.hpp)。

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.

然而,当我尝试编译项目时,我立即得到大量的C2061(语法错误标识符)错误来自cmath关于acosf,asinf,atanf等。

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.

cmath中的错误行:

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;

相关C ++文件的顶部块(虽然命名为.C):

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;

后跟main()函数,它不直接调用任何trig函数。
这是一个很明显的东西,但我错过了。任何人都可以帮助?

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?

谢谢!

推荐答案

编译为C ++?大多数编译器将.C文件编译为C,将.cpp文件编译为C ++,用C编译器编译C ++文件可能会失败。

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.

('c')headers和newstyle('c ++')headers。它应该更像这样(我怀疑是错误,然而)。

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;

这是我能看到你所提供的。但大多数时候,当你在C / C ++本身的库文件中得到错误,它仍然是你的代码在某个地方错了,像忘记;在头文件中的类语句之后。

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.

这篇关于在VS2010中编译旧的C ++代码时,cmath编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 16:08