第五章:
Linux下的C语言编程
姓名:
学号:520913080429
专业:信息安全09-04
实验内容:
1.c语言编程
2.vi编辑器
<编辑器
4.gdb编辑器
5. gdb中运行Linux的shell程序
6.make
1.c语言编程一般模式
编辑模式
[root@localhost home]# cd /home/
[root@localhost home]# vi hl.c
You have new mail in /var/spool/mail/root
linux的vi编辑器命令[root@localhost home]# ls
hl.c  student  vmware-tools-distrib
[root@localhost home]#
在调用C 语言编译器的时候,可以通过给出“ -I ”编译命令标志来引用保存在下级子目录或者非标准位置的头文件,类似命令如下:
[david@localhost linux]$ gcc -I /usr/openwin/include hello.c
先进入/usr/include 子目录,然后在grep 命令里给出该名字的几个字母,如下所示:
[david@localhost linux]$ grep KEYSPAN *.h
pci_ids.h:#define PCI_SUBVENDOR_ID_KEYSPAN      0x11a9
pci_ids.h:#define PCI_SUBDEVICE_ID_KEYSPAN_SX2  0x5334
2. v i 编辑器
[root@localhost ~]# cd /home
[root@localhost home]# vi cl.c
[root@localhost home]#
<编辑器
gcc的版本可以使用如下gcc –v命令查看:
[david@DAVID david]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/
sr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-
ystem-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
以上显示的就是Redhat linux 9.0里自带的gcc的版本3.2.2。
下面将以一个实例来说明如何使用gcc编译器。例3-1能够帮助大家迅速理解gcc的工作原理,并将其立即运用到实际的项目开发中去。
实例3-1 hello.c¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
#include <stdio.h>
int main (int argc,char **argv) {
printf("Hello Linux\n");
}
[root@localhost home]# ls
cl.c student test.c vmware-tools-distrib
[root@localhost home]# gcc test.c
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld 返回1
[root@localhost home]# . /a.out
bash: /a.out: 没有那个文件或目录
[root@localhost home]# gcc test.c -o test.i
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld 返回1
[root@localhost home]#

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。