配置 Qt 项目(.pro 文件)以使用 PcapPlusPlus
Configure Qt project (.pro file) to use 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}
我想在我的 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}