如何在 C++ 中包含流程工具程序?

发布于 2025-01-03 21:06:43 字数 480 浏览 1 评论 0原文

在我们的 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 技术交流群。

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

发布评论

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

评论(2

如歌彻婉言 2025-01-10 21:06:43

它声称是一个提供 API 的库,所以我希望它是可能的,甚至是有意的。

如果您想使用它,则需要构建该库,将其链接到您的应用程序,并使用文档(包括使用该库的随附命令行工具的源代码)来了解如何使用该 API。


好的,我目前的理解是标头和库已安装在您的系统上,并且您正在使用 Debian 包管理。

首先,您需要知道库和头文件在哪里,这样您就可以告诉您的构建系统在哪里可以找到它们:尝试

$ dpkg-query -L flow-tools

它应该为您提供流程工具头文件和库的安装目录。

因此,下一步是使这些标头和库可供您的构建系统使用:如果它们位于 /usr/lib/usr/local/lib>/usr/include/usr/local/include,您可以跳过这些路径。例如,如果您使用 make 进行构建,您可以添加一些内容,例如

FLOW_TOOLS_INC = <directory containing .h files>
FLOW_TOOLS_LIB = <directory containing .a file(s)>
CXXFLAGS += -I$(FLOW_TOOLS_INC) -L$(FLOW_TOOLS_LIB)

您还需要添加特定的库。

CXXFLAGS += -lft

现在(正如 zr. 所说)您需要将 API 声明带入您的源代码并开始对其进行编写,如下所示:

extern "C" {             // it is a C library, and we're building C++ (right?)
#include <flow-tools.h>  // or whatever the file name is
}

有关在构建该库后如何使用该库的更具体详细信息,请参阅附带的命令行实用程序的文档和源代码它(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

$ dpkg-query -L flow-tools

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 with make, you can add something like

FLOW_TOOLS_INC = <directory containing .h files>
FLOW_TOOLS_LIB = <directory containing .a file(s)>
CXXFLAGS += -I$(FLOW_TOOLS_INC) -L$(FLOW_TOOLS_LIB)

you'll need to add the specific library as well

CXXFLAGS += -lft

Now (as zr. said) you need to bring the API declaration into your source code and start writing against it, like so:

extern "C" {             // it is a C library, and we're building C++ (right?)
#include <flow-tools.h>  // or whatever the file name is
}

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.

扬花落满肩 2025-01-10 21:06:43

您提到您可以选择在 C++ 代码中使用 C 库。它的完成方式与使用 C++ 库非常相似,唯一的区别是你用 'extern "C" ' 包装你的声明:

extern "C" {
   #include "c-lib-header.h"
 }

int main() {
 c_func1();
}

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" ':

extern "C" {
   #include "c-lib-header.h"
 }

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