配置Qt项目(.pro文件)以使用PcapPlusPlus



我想在我的Qt项目中使用Pcap++。我遵循了安装中的步骤&PcapPlusPlus的介绍指南,但仍有未知之处:

  • 如何在.pro文件中实现它:include ../../../Dist/mk/PcapPlusPlus.mk
  • 而且:
all: 
g++.exe $(PCAPPP_INCLUDES) -c -o main.o main.cpp
g++.exe $(PCAPPP_LIBS_DIR) -static-libgcc -static-libstdc++ -o Tutorial-LiveTraffic.exe main.o $(PCAPPP_LIBS)

我已经这样添加了我的LIBS和INCLUDEPATH:

LIBS += -L/usr/local/lib/libCommon++.a -lCommon++
LIBS += -L/usr/local/lib/libPacket++.a -lPacket++
LIBS += -L/usr/local/lib/libPcap++.a -lPcap++
LIBS += -lpcap
INCLUDEPATH += /usr/local/include/pcapplusplus

举个例子,当我试图在我的主要函数中调用如下代码时:

#include <IPv4Layer.h>
#include <Packet.h>
#include <PcapFileDevice.h>

int main(int argc, char** argv) {
pcpp::PcapFileReaderDevice reader("the/path/example-app/1_packet.pcap");
return 0;
}

我有很多这样的错误:

/tmp/cirrus-ci-build/PcapPlusPlus/Common++/header/Logger.h:173: error : undefined reference to `pcpp::LoggerPP::LoggerPP()'

我们的想法是将.mk转换为qmake能够理解的适当代码,例如,在我的案例中,.mk是:

PCAPPLUSPLUS_HOME := /home/developer/PcapPlusPlus-20.08
### COMMON ###
# includes
PCAPPP_INCLUDES := -I$(PCAPPLUSPLUS_HOME)/Dist/header
# libs dir
PCAPPP_LIBS_DIR := -L$(PCAPPLUSPLUS_HOME)/Dist
# libs
PCAPPP_LIBS := -lPcap++ -lPacket++ -lCommon++
# post build
PCAPPP_POST_BUILD :=
# build flags
PCAPPP_BUILD_FLAGS :=
ifdef PCAPPP_ENABLE_CPP_FEATURE_DETECTION
PCAPPP_BUILD_FLAGS += -DPCAPPP_CPP_FEATURE_DETECTION -std=c++11
endif
ifndef CXXFLAGS
CXXFLAGS := -O2 -g -Wall
endif
PCAPPP_BUILD_FLAGS += $(CXXFLAGS)
### LINUX ###
# includes
PCAPPP_INCLUDES += -I/usr/include/netinet
# libs
PCAPPP_LIBS += -lpcap -lpthread
# allow user to add custom LDFLAGS
PCAPPP_BUILD_FLAGS += $(LDFLAGS)

因此,使用以前的信息构建以下。pro:

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += 
main.cpp
PCAPPLUSPLUS_HOME = /home/developer/PcapPlusPlus-20.08
PCAPPP_INCLUDES = $${PCAPPLUSPLUS_HOME}/Dist/header
PCAPPP_LIBS_DIR = -L$${PCAPPLUSPLUS_HOME}/Dist
PCAPPP_LIBS = -lPcap++ -lPacket++ -lCommon++
PCAPPP_POST_BUILD =
PCAPPP_BUILD_FLAGS =
defined(!PCAPPP_ENABLE_CPP_FEATURE_DETECTION){
PCAPPP_BUILD_FLAGS += -DPCAPPP_CPP_FEATURE_DETECTION -std=c++11
}
defined(!CXXFLAGS){
CXXFLAGS = -O2 -g -Wall
}
PCAPPP_BUILD_FLAGS += $${CXXFLAGS}
PCAPPP_INCLUDES += -I/usr/include/netinet
PCAPPP_LIBS += -lpcap -lpthread
PCAPPP_BUILD_FLAGS += $${LDFLAGS}
LIBS += $${PCAPPP_LIBS}
INCLUDEPATH += $${PCAPPP_INCLUDES}
DEPENDPATH += $${PCAPPP_LIBS_DIR}

相关内容

  • 没有找到相关文章

最新更新