系统头文件/usr/include/i386_types.h中出错 [英] Error in system header file /usr/include/i386_types.h

查看:292
本文介绍了系统头文件/usr/include/i386_types.h中出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用C / C ++约7个月,目前正在尝试写一小组线性代数程序。现在我试图测试我的向量类,但得到错误消息:

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’

在/usr/include/c++/4.2.1/stdexcept:43包含的文件中,
来自vector.cpp:8:
/usr/include/c++/4.2.1/exception:40:错误:此处不允许使用#pragma

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



我正在运行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)是:

The offending line (37) from _types.h is:

#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。我在运行gcc / g ++ - 4.2.1 on mac os x 10.6.5。

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.

推荐答案

通常在C ++中包括系统头您需要的文件 ,后跟您的应用程序头文件。尝试重新排序包含并查看是否有帮助:

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:

#include <cstdlib>
#include <cmath>

#include "linalg.h"

您包含与当前模块对应的头文件:

The exception to this is when you're including the header file that corresponds to the current module:

#include "linalg.h"

#include <cmath>
// etc

#include "utils.h" // or whatever

如果你这样做,它将确保你的 linalg.h 头可以包含在任何地方,它总是包括它自己需要的东西,而不是依赖用户首先包括系统内容。

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.

这篇关于系统头文件/usr/include/i386_types.h中出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆