红联Linux门户
Linux帮助
当前位置: 红联Linux门户 > Ubuntu

UBUNTU8.04-LIBC-C开发库安装及C程序编译全过程

发布时间:2008-08-18 10:13:08来源:红联作者:Cimsbbl
一、打开文本编辑器,写以下代码:

引用:
#include
int main(void){
printf("hello!linux programing world\n");
return 0;
}


然后存为hello.c源程序文件

笔者的源程序文件放在programs目录中

二、直接编译,打开终端(点击应用程序-附件-终端)

引用:
teacher@teacher-laptop:~/programs$ gcc hello.c -o hello
teacher@teacher-laptop:~/programs$ ./hello
hello!linux programing world


三、分次编译
-E 预处理
teacher@teacher-laptop:~/programs$ gcc -E hello.c -o hello.cpp
预处理后,可以看到很多头文件内容已经加入hello.cpp中

引用:
.....
.....
.....
.....
extern int fputs (__const char *__restrict __s, FILE *__restrict __stream);

extern int puts (__const char *__s);

extern int ungetc (int __c, FILE *__stream);

extern size_t fread (void *__restrict __ptr, size_t __size,
size_t __n, FILE *__restrict __stream) ;

extern size_t fwrite (__const void *__restrict __ptr, size_t __size,
size_t __n, FILE *__restrict __s) ;

# 706 "/usr/include/stdio.h" 3 4
extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
size_t __n, FILE *__restrict __stream) ;
extern size_t fwrite_unlocked (__const void *__restrict __ptr, size_t __size,
size_t __n, FILE *__restrict __stream) ;

extern int fseek (FILE *__stream, long int __off, int __whence);

extern long int ftell (FILE *__stream) ;

extern void rewind (FILE *__stream);

# 742 "/usr/include/stdio.h" 3 4
extern int fseeko (FILE *__stream, __off_t __off, int __whence);

extern __off_t ftello (FILE *__stream) ;
# 761 "/usr/include/stdio.h" 3 4

extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);

extern int fsetpos (FILE *__stream, __const fpos_t *__pos);
# 784 "/usr/include/stdio.h" 3 4

# 793 "/usr/include/stdio.h" 3 4

extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__));

extern int feof (FILE *__stream) __attribute__ ((__nothrow__)) ;

extern int ferror (FILE *__stream) __attribute__ ((__nothrow__)) ;

extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__));
extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__)) ;
extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__)) ;

extern void perror (__const char *__s);

# 1 "/usr/include/bits/sys_errlist.h" 1 3 4
# 27 "/usr/include/bits/sys_errlist.h" 3 4
extern int sys_nerr;
extern __const char *__const sys_errlist[];
# 823 "/usr/include/stdio.h" 2 3 4

extern int fileno (FILE *__stream) __attribute__ ((__nothrow__)) ;

extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__)) ;
# 842 "/usr/include/stdio.h" 3 4
extern FILE *popen (__const char *__command, __const char *__modes) ;

extern int pclose (FILE *__stream);

extern char *ctermid (char *__s) __attribute__ ((__nothrow__));
# 882 "/usr/include/stdio.h" 3 4
extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__));

extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__)) ;

extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__));
# 912 "/usr/include/stdio.h" 3 4

# 2 "hello.c" 2
int main(void){
printf("hello!linux programing world\n");
return 0;
}

-C 编译成目标文件
teacher@teacher-laptop:~/programs$ gcc -x cpp-output -c hello.cpp -o hello.o
-o链接
teacher@teacher-laptop:~/programs$ gcc hello.o -o hello
teacher@teacher-laptop:~/programs$ hello


四、对于没有安装C开发库的UBnutu系统来说,会出现编译错误,提示找到stdio.h文件和目录,就手动安装libc,安装过程如下:

首先,打开菜单:系统-系统管理-新立得软件包管理器

然后,在其中选择LIBC的所有文件,下载安装后OK,安装是自动的,不需要人工配置。
文章评论

共有 0 条评论