cmath.h 和编译错误

发布于 2024-09-28 13:09:10 字数 930 浏览 3 评论 0原文

我曾经使用 math.h 没有任何问题。现在,我使用一个外部库,它本身有一个名为 math.h 的文件,但其中包含 < cmath>

将此库添加到我的项目中(或者甚至只是添加包含目录,而不触及代码)现在会生成大量来自 的错误。 cmath>

C:\Program Files\Microsoft Visual Studio 8\VC\include\cmath(18):错误 C2039:“acosf”:不是“全局命名空间”的成员

C:\Program Files\Microsoft Visual Studio 8\VC\include\cmath(18):错误 C2873:“acosf”:符号不能在 using 声明中使用

C:\Program Files\Microsoft Visual Studio 8\VC\include\cmath(18):错误 C2039:“asinf”:不是“全局命名空间”的成员

C:\Program Files\Microsoft Visual Studio 8\VC\include\cmath(18):错误 C2873:“asinf”:符号不能在 using 声明中使用

[etc等等...]

我不明白为什么会发生这种情况。我正在使用 Visual Studio 2005 并在互联网上查找,似乎这个问题在 VS 2008 下已解决。但是,我想留在 VS 2005...

包括 using namespace std; 到处,或者改变我的包含顺序似乎没有改变任何东西。定义 _STD_BEGIN 可以解决该错误,但会产生与 一样多的错误。 xlocinfo>

如何解决这个问题?

I used to work with math.h without any problem. Now, I use an external library which itself has a file called math.h, but which includes < cmath>.

Adding this library to my project (or even just adding the include directory, without touching the code) now generates tons of errors from < cmath> :

C:\Program Files\Microsoft Visual Studio 8\VC\include\cmath(18) : error C2039: 'acosf' : is not a member of '`global namespace''

C:\Program Files\Microsoft Visual Studio 8\VC\include\cmath(18) : error C2873: 'acosf' : symbol cannot be used in a using-declaration

C:\Program Files\Microsoft Visual Studio 8\VC\include\cmath(18) : error C2039: 'asinf' : is not a member of '`global namespace''

C:\Program Files\Microsoft Visual Studio 8\VC\include\cmath(18) : error C2873: 'asinf' : symbol cannot be used in a using-declaration

[etc, etc...]

I don't understand why this happens. I am using Visual Studio 2005 and looking on the internet, it seems that this problem is solved under VS 2008. However, I'd like to stay on VS 2005...

Including using namespace std; everywhere, or changing the order of my includes doesn't seem to change anything. Defining _STD_BEGIN solves the error, but produce as many in < xlocinfo>.

How can this be solved?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

獨角戲 2024-10-05 13:09:10

VC 10 中也存在同样的问题。我认为 本身包含一个 math.h 但插入了正确的一个,它随 VC 一起提供,它使用一个是在用户项目中创建的(当然内容不同)。

解决方案:切勿在项目中使用名为 math.h 的文件...(或在某处更正 std)。

Same Problem exists in VC 10. I think, that <cmath> includes itself a math.h but insted of the correct one, which is shipped with VC it uses the one which is created in the User-Project (with different content of course).

Solution: Do never use a File named math.h in your Project... (Or correct the std somewhere).

じ违心 2024-10-05 13:09:10

我不确定我是否正确地阅读了你的问题,但图书馆会提供自己的 math.h 文件似乎很奇怪。

也许您应该将父目录放入包含路径中,以便可以包含 而不会与编译器 发生冲突>?

I'm not sure I read your question correctly but it seems odd that a library would ship it's own math.h file.

Perhaps you are suppose to put the parent directory in your include path so that <my_lib/math.h> can be included without conflicting with your compiler <math.h>?

懒的傷心 2024-10-05 13:09:10

问题可能在于将 C 库与 C++ 约定混合在一起。例如:

#include <math.h>
namespace TEST {
}

这编译得很好,而:

namespace TEST {
  #include <math.h>
}

这会生成大量虚假错误。

只是为了混淆这个问题:

#include <math.h>
namespace TEST {
  #include <math.h>
}

这也可以编译,因为它只能包含一次(第一次)。

因此也:

#include <math.h>
namespace TEST {
  #include "SomethingThatIncludesMath.h"
}

会起作用,而:

namespace TEST {
  #include "SomethingThatIncludesMath.h"
}

不会。

通过将 C++ 头文件包含到 *.c 文件(而不是 *.cpp 文件)中,您也可能会遇到类似的问题。

我确信 C 和 C++ 的其他类似混合也会导致类似的问题。

The problem is probably mixing C libraries with C++ conventions. For instance:

#include <math.h>
namespace TEST {
}

This compiles fine, whereas:

namespace TEST {
  #include <math.h>
}

This generates a large number of spurious errors.

Just to confuse the issue:

#include <math.h>
namespace TEST {
  #include <math.h>
}

This also compiles as it can only be included once (the first time).

Hence also:

#include <math.h>
namespace TEST {
  #include "SomethingThatIncludesMath.h"
}

Will work, whereas:

namespace TEST {
  #include "SomethingThatIncludesMath.h"
}

Won't.

You can also get similar problems by including C++ headers into a *.c file, rather than a *.cpp file.

I am sure that other similar mixing of C and C++ can lead to similar problems.

倒数 2024-10-05 13:09:10

(1) 根据 Microsoft 的说法,C2873 是指;

'symbol' :符号不能在 using 声明中使用
using 指令缺少名称空间关键字。这会导致编译器将代码误解为 using 声明而不是 using 指令。

(2)另外,当我有 C2873 和 C2039 时(我尝试合并 CEF3 和 Cinder),不知何故,我通过更改 Properties->Configuration Properties->C/C++->Code Generation 绕过了这两个错误;

启用最小重建:是(/Gm),启用 C++ 异常:是(/EHsc),启用功能级链接:空

(1) According to Microsoft, the C2873 means;

'symbol' : symbol cannot be used in a using-declaration
A using directive is missing a namespace keyword. This causes the compiler to misinterpret the code as a using declaration rather than a using directive.

(2) Also when I had C2873 with C2039 (I tried to merge CEF3 and Cinder), somehow I bypassed the both error by changing Properties->Configuration Properties->C/C++->Code Generation;

Enable Minimal Rebuild: Yes(/Gm), Enable C++ Exception: Yes(/EHsc), Enable Function-Level Linking: empty

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文