结论:
1,c语言的扩展名为.c的源文件可以使用cc或gcc编译器进行编译后,变成可执行文件
2,gcc或cc编译时,需要另一个文件makefile
3,makefile里面就是一个用于编译环境的配置信息,里面记录了各个操作系统平台和CPU处理器内核的配置信息
4,如何makefile里面没有你当前数据库版本的配置信息,需要你添加对应的操作系统配置信息
5,编译指令为
cc -o nmon_x86_64_rhel54 lmon.c -g -O2 -D JFS -D GETUSER -Wall -D LARGEMEM -lncurses -g
(可以不需要makefile文件也可以用上述指令编译成功)
6,上述第5步运行编译期间若报没有ncurses.h,请安装ncurses-devel开发包即可
测试过程
1,操作系统版本
[root@seconary ~]# more /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
[root@seconary ~]#
2,下载redhat5.4 nmon安装介质
http://sourceforge.net/projects/nmon/files
3,上传nmon安装介质
[root@seconary ~]# mkdir -p /nmon_test
[root@seconary ~]# cd /nmon_test/
[root@seconary nmon_test]#
4,安装编译nmon
[root@seconary nmon_test]# ll
total 196
-rwxrwxrwx 1 root root 185939 Aug 10 2010 lmon14a.c
-rwxrwxrwx 1 root root 4154 May 3 10:37 makefile
5,重命名上述头文件lmon14a.c
[root@seconary nmon_test]# mv lmon14a.c lmon.c
6,makefile文件添加如下2行新内容(添加一直报错),其实就是编译要用到makefile文件
[root@seconary nmon_test]# tail -2f makefile
cc -o nmon_x86_64_rhel54 $(FILE) $(CFLAGS) $(LDFLAGS) -D X86
cc -o nmon15cs lmon15c_stealing.c $(CFLAGS) $(LDFLAGS) -D X86
7,编译报错
[root@seconary nmon_test]# make nmon_x86_rhel54
gcc44 -o nmon_x86_rhel54 lmon.c -g -O3 -D JFS -D GETUSER -Wall -D LARGEMEM -lm -lncurses -g -D X86
make: gcc44: Command not found
make: *** [nmon_x86_rhel54] Error 127
8,修改makefile对应部分,gcc44改为gcc(很简单因为找不到gcc44,所以改为gcc)
nmon_x86_rhel54: $(FILE)
gcc -o nmon_x86_rhel54 $(FILE) $(CFLAGS) $(LDFLAGS) -D X86
9,再次编译报错
[root@seconary nmon_test]# cc -o nmon_x86_64_rhel54 lmon.c -g -O2 -D JFS -D GETUSER -Wall -D LARGEMEM -lncurses -g
lmon.c:35:21: error: ncurses.h: No such file or directory
10,已经安装了ncurses软件包
[root@seconary nmon_test]# rpm -qa|grep ncurses
ncurses-5.5-24.20060715
ncurses-5.5-24.20060715
[root@seconary nmon_test]#
11,加载操作系统 光盘
[root@seconary Server]# mount /dev/cdrom /mnt
[root@seconary Server]# pwd
/mnt/Server
12,可见已经安装了ncurses软件包,但没有安装ncurses-devel软件包
[root@seconary Server]# ll -l *curse*
-r--r--r-- 348 root root 1183178 Jan 18 2007 ncurses-5.5-24.20060715.i386.rpm
-r--r--r-- 141 root root 1209755 Jan 18 2007 ncurses-5.5-24.20060715.x86_64.rpm
-r--r--r-- 333 root root 1709697 Jan 18 2007 ncurses-devel-5.5-24.20060715.i386.rpm
-r--r--r-- 141 root root 1790863 Jan 18 2007 ncurses-devel-5.5-24.20060715.x86_64.rpm
-r--r--r-- 135 root root 42838 Mar 25 2009 php-ncurses-5.1.6-23.2.el5_3.x86_64.rpm
[root@seconary Server]# rpm -qa|grep ncurse
ncurses-5.5-24.20060715
ncurses-5.5-24.20060715
13,进行安装ncurses-devel软件包
安装了ncurses-devel还是找不到curse.h的头文件
[root@seconary Server]# rpm -ivh ncurses-devel-5.5-24.20060715.x86_64.rpm
Preparing... ########################################### [100%]
1:ncurses-devel ########################################### [100%]
[root@seconary Server]#
[root@seconary Server]#
[root@seconary Server]# locate curses.h
[root@seconary Server]# locate ncurses.h
[root@seconary Server]# rpm -ivh ncurses-devel-5.5-24.20060715.i386.rpm
Preparing... ########################################### [100%]
1:ncurses-devel ########################################### [100%]
[root@seconary Server]#
[root@seconary Server]#
[root@seconary Server]#
[root@seconary Server]# locate ncurses.h
[root@seconary Server]# locate curses.h
14,locate查不到头文件,但其实是存在的
[root@seconary Server]# cd /usr/include
[root@seconary include]# ll *ses*h
-rw-r--r-- 1 root root 2115 Jul 17 2009 aliases.h
lrwxrwxrwx 1 root root 16 Sep 4 03:53 curses.h -> ncurses/curses.h
lrwxrwxrwx 1 root root 17 Sep 4 03:53 ncurses.h -> ncurses/ncurses.h
15,更新locate元数据库,locate运行成功
[root@seconary include]# updatedb
You have new mail in /var/spool/mail/root
[root@seconary include]# locate curses.h
/usr/include/curses.h
/usr/include/ncurses.h
/usr/include/ncurses/curses.h
/usr/include/ncurses/ncurses.h
/usr/include/ncursesw/curses.h
/usr/include/ncursesw/ncurses.h
16,编译nmon成功
[root@seconary nmon_test]# cc -o nmon_x86_64_rhel54 lmon.c -g -O2 -D JFS -D GETUSER -Wall -D LARGEMEM -lncurses -g
[root@seconary nmon_test]#
17,编译成功当前目录多了一个文件nmon_x86_64_rhel54
[root@seconary nmon_test]# ll
total 416
-rwxrwxrwx 1 root root 185939 Sep 4 03:39 lmon.c
-rwxrwxrwx 1 root root 4250 Sep 4 03:34 makefile
-rwxr-xr-x 1 root root 219751 Sep 4 03:58 nmon_x86_64_rhel54
19,按n键实时监控网络性能,至于其它监控指标,请参考上述命令提示
[root@seconary ~]# mkdir -p /nmon_test
[root@seconary ~]# cd /nmon_test/
[root@seconary nmon_test]#
4,安装编译nmon
[root@seconary nmon_test]# ll
total 196
-rwxrwxrwx 1 root root 185939 Aug 10 2010 lmon14a.c
-rwxrwxrwx 1 root root 4154 May 3 10:37 makefile
5,重命名上述头文件lmon14a.c
[root@seconary nmon_test]# mv lmon14a.c lmon.c
6,makefile文件添加如下2行新内容(添加一直报错),其实就是编译要用到makefile文件
[root@seconary nmon_test]# tail -2f makefile
cc -o nmon_x86_64_rhel54 $(FILE) $(CFLAGS) $(LDFLAGS) -D X86
cc -o nmon15cs lmon15c_stealing.c $(CFLAGS) $(LDFLAGS) -D X86
7,编译报错
[root@seconary nmon_test]# make nmon_x86_rhel54
gcc44 -o nmon_x86_rhel54 lmon.c -g -O3 -D JFS -D GETUSER -Wall -D LARGEMEM -lm -lncurses -g -D X86
make: gcc44: Command not found
make: *** [nmon_x86_rhel54] Error 127
8,修改makefile对应部分,gcc44改为gcc(很简单因为找不到gcc44,所以改为gcc)
nmon_x86_rhel54: $(FILE)
gcc -o nmon_x86_rhel54 $(FILE) $(CFLAGS) $(LDFLAGS) -D X86
9,再次编译报错
[root@seconary nmon_test]# cc -o nmon_x86_64_rhel54 lmon.c -g -O2 -D JFS -D GETUSER -Wall -D LARGEMEM -lncurses -g
lmon.c:35:21: error: ncurses.h: No such file or directory
10,已经安装了ncurses软件包
[root@seconary nmon_test]# rpm -qa|grep ncurses
ncurses-5.5-24.20060715
ncurses-5.5-24.20060715
[root@seconary nmon_test]#
11,加载操作系统 光盘
[root@seconary Server]# mount /dev/cdrom /mnt
[root@seconary Server]# pwd
/mnt/Server
12,可见已经安装了ncurses软件包,但没有安装ncurses-devel软件包
[root@seconary Server]# ll -l *curse*
-r--r--r-- 348 root root 1183178 Jan 18 2007 ncurses-5.5-24.20060715.i386.rpm
-r--r--r-- 141 root root 1209755 Jan 18 2007 ncurses-5.5-24.20060715.x86_64.rpm
-r--r--r-- 333 root root 1709697 Jan 18 2007 ncurses-devel-5.5-24.20060715.i386.rpm
-r--r--r-- 141 root root 1790863 Jan 18 2007 ncurses-devel-5.5-24.20060715.x86_64.rpm
-r--r--r-- 135 root root 42838 Mar 25 2009 php-ncurses-5.1.6-23.2.el5_3.x86_64.rpm
[root@seconary Server]# rpm -qa|grep ncurse
ncurses-5.5-24.20060715
ncurses-5.5-24.20060715
13,进行安装ncurses-devel软件包
安装了ncurses-devel还是找不到curse.h的头文件
[root@seconary Server]# rpm -ivh ncurses-devel-5.5-24.20060715.x86_64.rpm
Preparing... ########################################### [100%]
1:ncurses-devel ########################################### [100%]
[root@seconary Server]#
[root@seconary Server]#
[root@seconary Server]# locate curses.h
[root@seconary Server]# locate ncurses.h
[root@seconary Server]# rpm -ivh ncurses-devel-5.5-24.20060715.i386.rpm
Preparing... ########################################### [100%]
1:ncurses-devel ########################################### [100%]
[root@seconary Server]#
[root@seconary Server]#
[root@seconary Server]#
[root@seconary Server]# locate ncurses.h
[root@seconary Server]# locate curses.h
14,locate查不到头文件,但其实是存在的
[root@seconary Server]# cd /usr/include
[root@seconary include]# ll *ses*h
-rw-r--r-- 1 root root 2115 Jul 17 2009 aliases.h
lrwxrwxrwx 1 root root 16 Sep 4 03:53 curses.h -> ncurses/curses.h
lrwxrwxrwx 1 root root 17 Sep 4 03:53 ncurses.h -> ncurses/ncurses.h
15,更新locate元数据库,locate运行成功
[root@seconary include]# updatedb
You have new mail in /var/spool/mail/root
[root@seconary include]# locate curses.h
/usr/include/curses.h
/usr/include/ncurses.h
/usr/include/ncurses/curses.h
/usr/include/ncurses/ncurses.h
/usr/include/ncursesw/curses.h
/usr/include/ncursesw/ncurses.h
16,编译nmon成功
[root@seconary nmon_test]# cc -o nmon_x86_64_rhel54 lmon.c -g -O2 -D JFS -D GETUSER -Wall -D LARGEMEM -lncurses -g
[root@seconary nmon_test]#
17,编译成功当前目录多了一个文件nmon_x86_64_rhel54
[root@seconary nmon_test]# ll
total 416
-rwxrwxrwx 1 root root 185939 Sep 4 03:39 lmon.c
-rwxrwxrwx 1 root root 4250 Sep 4 03:34 makefile
-rwxr-xr-x 1 root root 219751 Sep 4 03:58 nmon_x86_64_rhel54
19,按n键实时监控网络性能,至于其它监控指标,请参考上述命令提示
个人简介
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-1790929/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9240380/viewspace-1790929/