针对 libwireshark 进行编译
我正在尝试在 Ubuntu 10.10 上针对 libwireshark
编译一个程序。我已经安装了 wireshark-dev
软件包,它已在 /usr/lib/wireshark
和 /usr/include/wireshark
中安装了文件。
我的 C 源代码文件的头部包含一个 #include
指令,我的 gcc
命令行参数如下:
$ gcc -I/usr/include/wireshark `pkg-config --libs --cflags glib-2.0` -Wall -o test.out test.c -L/usr/lib/wireshark -lwireshark
但是,这会返回许多错误,包括:
/usr/lib/gcc/i686-linux-gnu/4.4.5/include/varargs.h:4: error: #error "GCC no longer implements <varargs.h>."
/usr/include/wireshark/epan/ftypes/ftypes.h:258: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘union’
我应该做什么来纠正这些问题?
I am attempting to compile a program against libwireshark
on Ubuntu 10.10. I have installed the wireshark-dev
package, which has installed files in /usr/lib/wireshark
and /usr/include/wireshark
.
The head of my C source code file contains a #include <epan/epan.h>
directive and my gcc
command line arguments are as follows:
$ gcc -I/usr/include/wireshark `pkg-config --libs --cflags glib-2.0` -Wall -o test.out test.c -L/usr/lib/wireshark -lwireshark
However, this returns many errors, including:
/usr/lib/gcc/i686-linux-gnu/4.4.5/include/varargs.h:4: error: #error "GCC no longer implements <varargs.h>."
/usr/include/wireshark/epan/ftypes/ftypes.h:258: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘union’
What should I do to rectify these issues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是一个用户不友好的包装和代码组织的简单案例。您需要首先包含 Wireshark 的“config”标头。我会这样写:
每当您包含此库中的标头时,请确保首先执行此操作。
我怎么知道的?我深入研究了 epan/proto.h,发现只有在未设置 HAVE_STDARG 时,它才会有条件地包含 varargs.h。然后我在
/usr/include/wireshark/
中grep
发现这个变量是在config.h
中设置的,所以我想它可能有必要将其包括在内,瞧,确实如此。我还需要添加 -lwiretap 以满足与 libwireshark 的链接。
wireshark-dev
组织中的另一个缺陷是它不依赖于(在包级别)wireshark-common
,即使后者确实提供了实际的>libwireshark.so
前一个符号链接到的。因此,您应该确保安装了wireshark-common
,或者/usr/lib/libwireshark.so
及其引用存在。It seems a simple case of user-unfriendly packaging and code organization. You need to include the "config" header for Wireshark first. I would write it this way:
Be sure that you do this first whenever you include headers from this library.
How did I know? I dug into
epan/proto.h
and found that it conditionally includesvarargs.h
only ifHAVE_STDARG
is not set. I thengrep
'd in/usr/include/wireshark/
and found this variable is set inconfig.h
, so I figured it might be necessary to include it, and lo, it was.I also needed to add
-lwiretap
to satisfy linkage withlibwireshark
.Another nit in the organization of
wireshark-dev
is that it does not depend (at the package level) onwireshark-common
, even though the latter does provide the actuallibwireshark.so
which the former symlinks to. So you should make sure thatwireshark-common
is installed, or that/usr/lib/libwireshark.so
and its referent exist.