如何在 C++ 中包含流程工具程序?
在我们的 C++ 程序中,我们想要处理 NetFlow 数据。我们发现的唯一用于执行此操作的工具是 flow-tools,我们使用它已安装并可从命令行 (Linux) 完美运行。
flow-tools 是用 C 语言编写的,因此我们认为可以将它用作 C++ 程序中的库,但我们不知道如何做到这一点。
flow-tools 的 gzip, ftp:// ftp.eng.oar.net/pub/flow-tools/flow-tools-0.66.tar.gz,包含文件的 c 源代码,依赖项位于 lib 文件夹中。
是否有可能做到这一点,以及如何做到?是否有流程工具的替代品?
In our C++ program we want to process NetFlow data. The only tool for doing this that we've found is flow-tools, which we've installed and are running perfectly from the command line (Linux).
flow-tools is written in c, therefore we thought it might be possible to use it as a library in a c++ program, but we have no idea how to do this.
The gzip for flow-tools, ftp://ftp.eng.oar.net/pub/flow-tools/flow-tools-0.66.tar.gz, includes the c-source of the files, and the dependencies are in the lib-folder.
Is it at all possible to do this, and how? Might there be an alternative to flow-tools?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它声称是一个提供 API 的库,所以我希望它是可能的,甚至是有意的。
如果您想使用它,则需要构建该库,将其链接到您的应用程序,并使用文档(包括使用该库的随附命令行工具的源代码)来了解如何使用该 API。
好的,我目前的理解是标头和库已安装在您的系统上,并且您正在使用 Debian 包管理。
首先,您需要知道库和头文件在哪里,这样您就可以告诉您的构建系统在哪里可以找到它们:尝试
它应该为您提供流程工具头文件和库的安装目录。
因此,下一步是使这些标头和库可供您的构建系统使用:如果它们位于
/usr/lib
或/usr/local/lib
和>/usr/include
或/usr/local/include
,您可以跳过这些路径。例如,如果您使用make
进行构建,您可以添加一些内容,例如您还需要添加特定的库。
现在(正如 zr. 所说)您需要将 API 声明带入您的源代码并开始对其进行编写,如下所示:
有关在构建该库后如何使用该库的更具体详细信息,请参阅附带的命令行实用程序的文档和源代码它(
apt-get 源流工具
应该得到这个,或者只使用您链接的 tarball)。有关如何配置构建系统的更具体细节,请参阅其文档,或提出另一个问题并实际说出它是什么。
It claims to be a library providing an API, so I expect it is possible, and even intended.
If you want to use it, you'll need to build the library, link it to your app, and use the documentation (including the source of the included commandline tools, which use that library) to figure out how to use the API.
OK, so my current understanding is that the headers and libraries are installed on your system, and you're using Debian package management.
First, you need to know where the libraries and headers files are, so you can tell your build system where to find them: try
it should give you the directories in which the flow tools headers and libs are installed.
So, next step is to make those headers and libraries available to your build system: if they're in
/usr/lib
or/usr/local/lib
and/usr/include
or/usr/local/include
, you can skip the paths. For example if you're building withmake
, you can add something likeyou'll need to add the specific library as well
Now (as zr. said) you need to bring the API declaration into your source code and start writing against it, like so:
For more concrete details of how to use the library once you're building against it, see the documentation and the source for the command-line utils that ship with it (
apt-get source flow-tools
should get this, or just use the tarball you linked).For more concrete details of how to configure your build system, see its documentation, or ask another question and actually say what it is.
您提到您可以选择在 C++ 代码中使用 C 库。它的完成方式与使用 C++ 库非常相似,唯一的区别是你用 'extern "C" ' 包装你的声明:
You mentioned that you may have an option of using a C library in your C++ code. It is done very similarly to using a C++ library, only difference is that you wrap your declaration with 'extern "C" ':