系统头文件/usr/include/i386_types.h错误
我已经使用 C/C++ 大约 7 个月了,目前正在尝试编写一小组线性代数程序。现在我正在尝试测试我的向量类,但收到错误消息:
In file included from /usr/include/machine/_types.h:34,
from /usr/include/sys/_types.h:33,
from /usr/include/_types.h:27,
from /usr/include/unistd.h:71,
from /usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/os_defines.h:61,
from /usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/c++config.h:41,
from /usr/include/c++/4.2.1/cstdlib:50,
from linalgtest.cpp:8:
/usr/include/i386/_types.h:37: error: two or more data types in declaration of ‘__int8_t’
In file include from /usr/include/c++/4.2.1/stdexcept:43, 来自向量.cpp:8: /usr/include/c++/4.2.1/exception:40: 错误:此处不允许使用“#pragma”
shell returned 1
我正在运行 Mac OS X 10.6.5,并检查了我的 /usr/include/i386_types.h
文件针对 http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/i386/_types.h。无论价值如何,它们看起来都是一样的。
以下是我的测试程序文件的内容
#include "linalg.h" // L7
#include <cstdlib> // L8: the offending line
#include <cmath> // L9
using namespace std;
double drand(double d) { return d*((double)rand()/RAND_MAX); }
int main(void) {
int n = 10;
double comps[10];
for (int i = 0; i < n; ++i)
comps[i] = drand(10.0);
vector *v1 = new vector(n);
vector *v2 = new vector(n, comps);
v1->print();
v2->print();
return 0;
}
_types.h 中的违规行 (37) 是:
#ifdef __GNUC__
typedef __signed char __int8_t; // L37
#else /* !__GNUC__ */
typedef char __int8_t;
来自异常 (40):
#ifndef __EXCEPTION__
#define __EXCEPTION__
#pragma GCC visibility push(default) // L40
#include <bits/c++config.h>
我在 Google 上进行了一些搜索,并看到了涉及类似类型错误的内容,但其结果通常是用户代码中的语法错误。我还在我大学计算机实验室的机器上看到了这个确切的错误。他们在 ubuntu lucid 上运行 gcc/g++-4.2.4。我在 mac os x 10.6.5 上运行 gcc/g++-4.2.1。
I've been using C/C++ for about 7 months, and am currently trying to write a small set of linear algebra programs. Right now I'm trying to test my vector class, but get the error message:
In file included from /usr/include/machine/_types.h:34,
from /usr/include/sys/_types.h:33,
from /usr/include/_types.h:27,
from /usr/include/unistd.h:71,
from /usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/os_defines.h:61,
from /usr/include/c++/4.2.1/i686-apple-darwin10/x86_64/bits/c++config.h:41,
from /usr/include/c++/4.2.1/cstdlib:50,
from linalgtest.cpp:8:
/usr/include/i386/_types.h:37: error: two or more data types in declaration of ‘__int8_t’
In file included from /usr/include/c++/4.2.1/stdexcept:43,
from vector.cpp:8:
/usr/include/c++/4.2.1/exception:40: error: ‘#pragma’ is not allowed here
shell returned 1
I am running Mac OS X 10.6.5, and have checked my /usr/include/i386_types.h
file against the one found at http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/bsd/i386/_types.h. They appear to be the same, for whatever that's worth.
Here are the contents of my tester file
#include "linalg.h" // L7
#include <cstdlib> // L8: the offending line
#include <cmath> // L9
using namespace std;
double drand(double d) { return d*((double)rand()/RAND_MAX); }
int main(void) {
int n = 10;
double comps[10];
for (int i = 0; i < n; ++i)
comps[i] = drand(10.0);
vector *v1 = new vector(n);
vector *v2 = new vector(n, comps);
v1->print();
v2->print();
return 0;
}
The offending line (37) from _types.h is:
#ifdef __GNUC__
typedef __signed char __int8_t; // L37
#else /* !__GNUC__ */
typedef char __int8_t;
From exception (40):
#ifndef __EXCEPTION__
#define __EXCEPTION__
#pragma GCC visibility push(default) // L40
#include <bits/c++config.h>
I've done some searching on Google, and seen things involving similar types of errors, but its usually the result of a syntax error in user code. I also see this exact error on the machines in my university's computer lab. They run gcc/g++-4.2.4 on ubuntu lucid. I run gcc/g++-4.2.1 on mac os x 10.6.5.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常在 C++ 中,首先包含需要的系统头文件,然后是应用程序头文件。尝试重新排序包含内容,看看是否有帮助:
vector.cpp
例外情况是当您包含与当前模块相对应的头文件时:
linalg.cpp
如果您这样做,它将确保您的
linalg.h
标头可以包含在任何地方,并且它始终包含其自身所需的内容,而不是依赖用户首先包含系统内容。Usually in C++ you include the system header file(s) you need first, followed by your application header files. Try reordering the includes and see if that helps:
vector.cpp
The exception to this is when you're including the header file that corresponds to the current module:
linalg.cpp
If you do this, it will ensure that your
linalg.h
header can be included everywhere and it always includes stuff it needs from itself, rather than relying on users to include system things first.