编译旧 C++ 时 cmath 编译错误VS2010中的代码
我继承了一些 C++ 文件和一个附带的 makefile,我试图将其作为解决方案引入 VS2010。我创建了一个空项目,并为 makefile 目标之一添加了适当的 C++ 和头文件 (.hpp)。
然而,当我尝试编译该项目时,我立即收到来自 cmath 的大量关于 acosf、asinf、atanf 等的 C2061(语法错误标识符)错误。
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):
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
后面是 main() 函数,它不直接调用任何三角函数。 这一定是非常明显的事情,但我错过了。有人可以帮忙吗?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你确定它编译为 C++ 吗?大多数编译器会将 .C 文件编译为 C,将 .cpp 文件编译为 C++,使用 C 编译器编译 C++ 文件可能会失败。
此外,该代码混合了旧式('c')标头和新式('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.
Also, that code mixes oldstyle ('c') headers and newstyle ('c++') headers. It should be more like this (I doubt that is the error however).
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.
正如您所假设的,它可能不会编译为 C++ 代码。我会要求你在vs2010中右键单击该文件,单击属性,转到“配置属性 - C/C++ - 高级”,并确保“编译为”设置为“编译为C++代码(/TP)” '..如果不是,请将其更改为该值,然后重新编译..您可能需要重新创建预编译标头,但我将解决您的“问题”;)
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' ;)