在ubuntu上编译简单的gcc,显示一大堆错误

Web、Mail、Ftp、DNS、Proxy、VPN、Samba、LDAP 等基础网络服务
回复
double_flower
帖子: 3
注册时间: 2016-08-01 14:48
系统: ubuntu14.02

在ubuntu上编译简单的gcc,显示一大堆错误

#1

帖子 double_flower » 2016-08-01 15:12

首先我通过uname -a查看系统信息:
Linux tegra-ubuntu 3.10.67-g3a5c467 #1 SMP PREEMPT Fri Oct 30 14:26:17 PDT 2015 aarch64 aarch64 aarch64 GNU/Linux
编写一个简单的程序hello.c:
#include "stdio.h"
int main(void)
{
printf("Hello world!");
return 0;
}
执行命令‘gcc hello.c’,
显示如下错误:
gaojianhua@tegra-ubuntu:~/cuda_learn$ gcc hello.c
In file included from /usr/local/include/forwards.h:10:0,
from /usr/local/include/features.h:10,
from /usr/include/stdio.h:27,
from hello.c:1:
/usr/local/include/config.h:116:1: error: unknown type name ‘namespace’
namespace Json {
^
/usr/local/include/config.h:116:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
namespace Json {
^
In file included from /usr/local/include/features.h:10:0,
from /usr/include/stdio.h:27,
from hello.c:1:
/usr/local/include/forwards.h:13:1: error: unknown type name ‘namespace’
namespace Json {
^
/usr/local/include/forwards.h:13:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
namespace Json {
^
In file included from /usr/include/stdio.h:27:0,
from hello.c:1:
/usr/local/include/features.h:13:1: error: unknown type name ‘namespace’
namespace Json {
^
/usr/local/include/features.h:13:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
namespace Json {
^
In file included from /usr/include/stdio.h:33:0,
from hello.c:1:
/usr/lib/gcc/arm-linux-gnueabihf/4.8/include/stddef.h:212:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘typedef’
typedef __SIZE_TYPE__ size_t;
^
In file included from hello.c:1:0:
/usr/include/stdio.h:48:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘typedef’
typedef struct _IO_FILE FILE;
^
/usr/include/stdio.h:64:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘typedef’
typedef struct _IO_FILE __FILE;
^
In file included from /usr/include/libio.h:56:0,
from /usr/include/stdio.h:74,
from hello.c:1:
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:41:20: error: missing binary operator before token "("
# if __GNUC_PREREQ (4, 6) && !defined _LIBC
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:54:44: error: missing binary operator before token "("
# if !defined __cplusplus && __GNUC_PREREQ (3, 3)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:59:44: error: missing binary operator before token "("
# if defined __cplusplus && __GNUC_PREREQ (2,8)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:136:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (4,3)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:149:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (2,97)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:211:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (2,96)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:219:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (4, 3)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:229:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (2,96)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:236:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (2,5)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:245:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (3,1)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:254:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (3,2)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:266:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (2,8)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:276:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (2,97)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:285:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (3,3)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:293:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (3,4)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:307:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (3,2)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:315:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (4,3)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:341:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (4,3)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:350:20: error: missing binary operator before token "("
#if !__GNUC_PREREQ (2,8)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:355:20: error: missing binary operator before token "("
#if !__GNUC_PREREQ (2,92)
^
/usr/include/arm-linux-gnueabihf/sys/cdefs.h:362:19: error: missing binary operator before token "("
#if __GNUC_PREREQ (3,1) && !defined __GNUG__
^
In file included from /usr/include/stdio.h:74:0,
from hello.c:1:
/usr/include/libio.h:306:3: error: unknown type name ‘size_t’
size_t __pad5;
^
/usr/include/libio.h:310:67: error: ‘size_t’ undeclared here (not in a function)
char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];
^
/usr/include/libio.h:338:62: error: expected declaration specifiers or ‘...’ before ‘size_t’
typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
^
/usr/include/libio.h:347:6: error: expected declaration specifiers or ‘...’ before ‘size_t’
size_t __n);
^
/usr/include/libio.h:469:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_IO_sgetn’
extern _IO_size_t _IO_sgetn (_IO_FILE *, void *, _IO_size_t);
^
In file included from hello.c:1:0:
/usr/include/stdio.h:195:1: error: unknown type name ‘FILE’
extern FILE *tmpfile (void) __wur;
^
/usr/include/stdio.h:237:20: error: unknown type name ‘FILE’
extern int fclose (FILE *__stream);
^
/usr/include/stdio.h:242:20: error: unknown type name ‘FILE’
extern int fflush (FILE *__stream);
^
/usr/include/stdio.h:272:1: error: unknown type name ‘FILE’
extern FILE *fopen (const char *__restrict __filename,
^
/usr/include/stdio.h:278:1: error: unknown type name ‘FILE’
extern FILE *freopen (const char *__restrict __filename,
^
/usr/include/stdio.h:280:9: error: unknown type name ‘FILE’
FILE *__restrict __stream) __wur;
^
/usr/include/stdio.h:332:21: error: unknown type name ‘FILE’
extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __THROW;
^
/usr/include/stdio.h:336:21: error: unknown type name ‘FILE’
extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
^
/usr/include/stdio.h:337:20: error: expected declaration specifiers or ‘...’ before ‘size_t’
int __modes, size_t __n) __THROW;
^
/usr/include/stdio.h:356:21: error: unknown type name ‘FILE’
extern int fprintf (FILE *__restrict __stream,
^
/usr/include/stdio.h:371:22: error: unknown type name ‘FILE’
extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
^
/usr/include/stdio.h:425:20: error: unknown type name ‘FILE’
extern int fscanf (FILE *__restrict __stream,
^
/usr/include/stdio.h:531:19: error: unknown type name ‘FILE’
extern int fgetc (FILE *__stream);
^
/usr/include/stdio.h:532:18: error: unknown type name ‘FILE’
extern int getc (FILE *__stream);
^
/usr/include/stdio.h:573:28: error: unknown type name ‘FILE’
extern int fputc (int __c, FILE *__stream);
^
/usr/include/stdio.h:574:27: error: unknown type name ‘FILE’
extern int putc (int __c, FILE *__stream);
^
/usr/include/stdio.h:622:52: error: unknown type name ‘FILE’
extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
^
/usr/include/stdio.h:689:47: error: unknown type name ‘FILE’
extern int fputs (const char *__restrict __s, FILE *__restrict __stream);
^
/usr/include/stdio.h:702:29: error: unknown type name ‘FILE’
extern int ungetc (int __c, FILE *__stream);
^
/usr/include/stdio.h:709:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread’
extern size_t fread (void *__restrict __ptr, size_t __size,
^
/usr/include/stdio.h:715:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite’
extern size_t fwrite (const void *__restrict __ptr, size_t __size,
^
/usr/include/stdio.h:749:19: error: unknown type name ‘FILE’
extern int fseek (FILE *__stream, long int __off, int __whence);
^
/usr/include/stdio.h:754:24: error: unknown type name ‘FILE’
extern long int ftell (FILE *__stream) __wur;
^
/usr/include/stdio.h:759:21: error: unknown type name ‘FILE’
extern void rewind (FILE *__stream);
^
/usr/include/stdio.h:798:21: error: unknown type name ‘FILE’
extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);
^
/usr/include/stdio.h:803:21: error: unknown type name ‘FILE’
extern int fsetpos (FILE *__stream, const fpos_t *__pos);
^
/usr/include/stdio.h:826:23: error: unknown type name ‘FILE’
extern void clearerr (FILE *__stream) __THROW;
^
/usr/include/stdio.h:828:18: error: unknown type name ‘FILE’
extern int feof (FILE *__stream) __THROW __wur;
^
/usr/include/stdio.h:830:20: error: unknown type name ‘FILE’
extern int ferror (FILE *__stream) __THROW __wur;


有没有大神能够帮忙解决一下。
头像
astolia
论坛版主
帖子: 6396
注册时间: 2008-09-18 13:11

Re: 在ubuntu上编译简单的gcc,显示一大堆错误

#2

帖子 astolia » 2016-08-01 19:55

自己乱装东西把编译环境弄乱了。本来该include的是/usr/include/features.h,结果弄成了/usr/local/include/forwards.h,导致c程序去引用c++的头文件,不出事才怪
double_flower
帖子: 3
注册时间: 2016-08-01 14:48
系统: ubuntu14.02

Re: 在ubuntu上编译简单的gcc,显示一大堆错误

#3

帖子 double_flower » 2016-08-01 20:01

那请问有什么解决办法吗
double_flower
帖子: 3
注册时间: 2016-08-01 14:48
系统: ubuntu14.02

Re: 在ubuntu上编译简单的gcc,显示一大堆错误

#4

帖子 double_flower » 2016-08-01 20:05

那请问有什么解决办法吗? :Sad
头像
astolia
论坛版主
帖子: 6396
注册时间: 2008-09-18 13:11

Re: 在ubuntu上编译简单的gcc,显示一大堆错误

#5

帖子 astolia » 2016-08-02 19:35

谁知道你装了些什么东西,怎么安装的就怎么卸载,不知道怎么卸就把/usr/local/include、/usr/local/lib、/usr/local/bin下面的东西删光

代码: 全选

echo | gcc -v -x c -E -
上面的命令会列出C程序头文件的查找路径和顺序,你别把可能导致混淆的东西直接安装到那些路径下面。
真要用的时候,编译时通过-I参数指定头文件所在目录就是了
头像
astolia
论坛版主
帖子: 6396
注册时间: 2008-09-18 13:11

Re: 在ubuntu上编译简单的gcc,显示一大堆错误

#6

帖子 astolia » 2016-08-02 19:59

我上面说过了,你先把安装的东西卸载干净。有事直接回帖,别滥用短信息
回复