Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top