getopt、getopt_long的可重入版本----linux交互式应用程序
来源:互联网 发布:comsol正规软件多少钱 编辑:程序博客网 时间:2024/05/16 04:18
00000000 l df *ABS* 00000000 getopt.c
00000000 l d .text 00000000 .text
00000000 l d .data 00000000 .data
00000000 l d .bss 00000000 .bss
00000000 l d .note.GNU-stack 00000000 .note.GNU-stack
00000000 l d .comment 00000000 .comment
说明编译出来的文件一个符号都没有,这样链接还是链接到c库,而c库里没有包含的函数,比如_getopt_long_r肯定是找不到了。
|
gcc -c test.c
objdump -t test.o
test.o: file format elf32-i386
SYMBOL TABLE:
00000000 l df *ABS* 00000000 test.c
00000000 l d .text 00000000 .text
00000000 l d .data 00000000 .data
00000000 l d .bss 00000000 .bss
00000000 l d .rodata 00000000 .rodata
00000000 l d .note.GNU-stack 00000000 .note.GNU-stack
00000000 l d .comment 00000000 .comment
00000000 g F .text 00000005 fun
00000005 g F .text 00000026 main
00000000 *UND* 00000000 puts
说明了一个问题,那就是getopt中的函数并没有真正进行编译。
要不然它应该会有类似下面的结果,符号表里应该包括fun,即函数名
在getopt.c如下位置添加#define _LIBC 和#define _(x) (x)
|
同理在getopt1.c中修改为
|
代码实例:
//test.c 和getopt.c getopt1.c getopt.h getopt_int.h在同一目录下
|
编译gcc test.c getopt.c getopt1.c
./a.out
运行结果
root@xsf-pc:/my/study/project# ./a.out -V
mysnort 0.0.1
此时,_getopt_long_r已经成功调用了,要使用这个做交互式应用程序,还需要自己定义函数实现argc,argv的重写,当然你也可以定义二维数组,将输入的参数字符串读入到二维数组中,然后将这个数组和数组包含的字符串数传入_getopt_long_r,二维数组必须以null结尾,而字符串数不包括null,具体怎么做,读者自己写写程序试试,在此就不剥夺读者自己写程序的权利了。由于_getopt_long_r是可重入的,你将正确解析的命令行字符串输入传入这个分析函数,就能进行连续分析了。这样linux的交互式程序设计就实现了。就像gdb似的。
你解析的参数应如下所示。
int n = 2;
char *argv[24] = {"help" , "-V", NULL};
上一篇:指针和数组一致的情况及二维数组初始化
下一篇:业界盘点:Linux和微软应该相互学习的5件事?
- 文件系统的制作 yaffs2 jffs2 ...
- java之路,基础知识5
- 从PHP官网被攻击,到熟悉SSL(...
- 进程上下文VS中断上下文...
- sowasp 2013 十大web应用程序...
- linux 常见服务端口
- 【ROOTFS搭建】busybox的httpd...
- 什么是shell
- linux socket的bug??
- linux的线程是否受到了保护?...
- ChinaUnix & ITPUB社区12周年...
- ssh连接出现以下提示,求解...
- 如何扩展MYSQL
- 准备做一个大型门户,用户什么...
- gbk or utf8
- getopt、getopt_long的可重入版本----linux交互式应用程序
- Linux选项-getopt/getopt_long
- linux c getopt getopt_long
- linux getopt 和getopt_long详解
- Linux getopt和getopt_long函数
- getopt和getopt_long的使用
- Linux选项解释-getopt和getopt_long函数
- Linux选项解释-getopt和getopt_long函数
- Linux getopt()函数 getopt_long()函数---转
- linux选项解释-getopt和getopt_long函数
- linux 中getopt和getopt_long 用法解析
- getopt函数与getopt_long函数的用法
- c++中getopt和getopt_long的使用方法
- c++中getopt和getopt_long的使用方法
- Linux解析命令行选项参数getopt和getopt_long
- linux 输入参数利用getopt、struct option、getopt_long、getopt_long_only解析
- getopt_long和 getopt
- getopt();getopt_long();getopt_long_only();option
- linux和windows的文件共享-使用ssh
- 磁盘空间不足--增加虚拟磁盘
- 数组和指针的类型转换
- 数组和指针并不相同
- 指针和数组一致的情况及二维数组初始化
- getopt、getopt_long的可重入版本----linux交互式应用程序
- 业界盘点:Linux和微软应该相互学习的5件事?
- fcitx的安装使用
- oracle 中 inner join内连接、 left join左连接、right join右连接用法
- wine QQ2008
- 编译ubuntu8.04内核
- lfs的介绍
- c/c++编程风格
- sizeof