针对 libwireshark 进行编译

发布于 2024-10-04 20:07:19 字数 748 浏览 3 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素衣风尘叹 2024-10-11 20:07:19

这似乎是一个用户不友好的包装和代码组织的简单案例。您需要首先包含 Wireshark 的“config”标头。我会这样写:

#include <wireshark/config.h> /* needed by epan */
#include <epan/epan.h>

每当您包含此库中的标头时,请确保首先执行此操作。

我怎么知道的?我深入研究了 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:

#include <wireshark/config.h> /* needed by epan */
#include <epan/epan.h>

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 includes varargs.h only if HAVE_STDARG is not set. I then grep'd in /usr/include/wireshark/ and found this variable is set in config.h, so I figured it might be necessary to include it, and lo, it was.

I also needed to add -lwiretap to satisfy linkage with libwireshark.

Another nit in the organization of wireshark-dev is that it does not depend (at the package level) on wireshark-common, even though the latter does provide the actual libwireshark.so which the former symlinks to. So you should make sure that wireshark-common is installed, or that /usr/lib/libwireshark.so and its referent exist.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文