在cmake中使用Pcap++库

pkln4tw6  于 2023-06-23  发布在  其他
关注(0)|答案(2)|浏览(231)

我现在正在把一个Qt Creator项目转换成一个cmake项目,不能再编译我的程序了。我使用库PcapPlusPlus作为一个子模块,因为我们做了一些主要的变化,原来的库。我使用他们的说明中建议的构建链,并在子模块中使用"./configure-linux--default"和"make libs"。所以到 *. a文件的路径是正确的。还提到该项目仍然可以使用Qt Creator(也具有相同的依赖项)进行编译。
这是我的CMakeLists.txt:

cmake_minimum_required(VERSION 3.16)
project(mitm)

set(CMAKE_PREFIX_PATH ~/Qt/5.15.0/gcc_64/lib/cmake/)

#pthread
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

#pcap
include(FindPCAP.cmake)

find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)

set(CMAKE_CXX_STANDARD 14)

include_directories(.)
include_directories("${CMAKE_SOURCE_DIR}/../Pcap++/header/")
include_directories("${CMAKE_SOURCE_DIR}/../Packet++/header/")
include_directories("${CMAKE_SOURCE_DIR}/../Common++/header/")

add_executable(mitm "")

set_target_properties(mitm PROPERTIES
        AUTOMOC ON
        AUTOUIC ON
        AUTORCC ON)

set(SOURCE_FILES
        classes/base/wrapper/connection.cpp
        classes/base/wrapper/connection.h
        classes/base/wrapper/connectionlist.cpp
        classes/base/wrapper/connectionlist.h
        classes/base/wrapper/hostlist.cpp
        classes/base/wrapper/hostlist.h
        classes/base/connectionmanager.cpp
        classes/base/connectionmanager.h
        main.cpp
        wmain.cpp
        wmain.h
        wmain.ui
        wsetup.cpp
        wsetup.h
        wsetup.ui)

set(RESOURCE_FILES
        fonts.qrc)

target_sources(mitm PRIVATE
        ${SOURCE_FILES}
        ${RESOURCE_FILES})

target_link_libraries(mitm PRIVATE
        Qt5::Widgets
        "${CMAKE_SOURCE_DIR}/../Common++/Lib/Release/libCommon++.a"
        "${CMAKE_SOURCE_DIR}/../Pcap++/Lib/libPcap++.a"
        "${CMAKE_SOURCE_DIR}/../Packet++/Lib/libPacket++.a"
        Threads::Threads
        ${PCAP_LIBRARY}
        )
/usr/bin/ld: ../../Pcap++/Lib/libPcap++.a(PcapLiveDevice.o): in function `pcpp::PcapLiveDevice::startCaptureBlockingMode(bool (*)(pcpp::RawPacket*, pcpp::PcapLiveDevice*, void*), void*, int)':
/home/bemerged/Documents/Git/mitm/Pcap++/src/PcapLiveDevice.cpp:492: undefined reference to `pcpp::clockGetTime(long&, long&)'
/usr/bin/ld: /home/bemerged/Documents/Git/mitm/Pcap++/src/PcapLiveDevice.cpp:512: undefined reference to `pcpp::clockGetTime(long&, long&)'
/usr/bin/ld: ../../Pcap++/Lib/libPcap++.a(PcapLiveDevice.o): in function `pcpp::PcapLiveDevice::getIPv4Address() const':
/home/bemerged/Documents/Git/mitm/Pcap++/src/PcapLiveDevice.cpp:905: undefined reference to `pcpp::sockaddr2in_addr(sockaddr*)'
/usr/bin/ld: /home/bemerged/Documents/Git/mitm/Pcap++/src/PcapLiveDevice.cpp:901: undefined reference to `pcpp::sockaddr2string(sockaddr*, char*)'
/usr/bin/ld: /home/bemerged/Documents/Git/mitm/Pcap++/src/PcapLiveDevice.cpp:905: undefined reference to `pcpp::sockaddr2in_addr(sockaddr*)'
/usr/bin/ld: ../../Pcap++/Lib/libPcap++.a(PcapLiveDevice.o): in function `pcpp::PcapLiveDevice::PcapLiveDevice(pcap_if*, bool, bool, bool)':
/home/bemerged/Documents/Git/mitm/Pcap++/src/PcapLiveDevice.cpp:101: undefined reference to `pcpp::sockaddr2string(sockaddr*, char*)'

到目前为止,我还是个新手,我已经尽了最大的努力。我确信这是pcap ++库中的链接问题。正如你可能猜到的,我现在在谷歌上搜索了大约2个小时,没有发现任何可以解决我的问题。

r6hnlfcb

r6hnlfcb1#

FindPCAP.cmake搜索lib pcap,C库。您正在使用C++与Pcap ++,并且应该额外链接lib pcaplusplus或Pcap ++和Packet ++。
cmake linking against static libraries - do you have to tell cmake where to look?

wz3gfoph

wz3gfoph2#

尝试此链接顺序
-lPcap++ -lPacket++ -lCommon++ -lpcap

相关问题