3

im currently converting a Qt Creator project to a cmake project and can't compile my program anymore. Im using the Library PcapPlusPlus as a submodule because we did some major changes to the original library. I use the buildchain suggested in their instructions and use "./configure-linux --default" and "make libs" within the submodule. So the path to the *.a files are correct. Also mentioning that the project can still be compiled with Qt Creator (which also has the same dependencies).

This is my 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*)'

Im pretty new to cmake und tried my best so far. Im sure this is a linking problem within the pcap++ library. As you might guess I googled around 2 hours now and found nothing to solve my problem.

273K
  • 29,503
  • 10
  • 41
  • 64
bemerged
  • 31
  • 5

2 Answers2

3

FindPCAP.cmake searches for lib pcap, C library. You are using C++ with Pcap++ and should additionally link with lib pcaplusplus or Pcap++ and Packet++.

cmake linking against static libraries - do you have to tell cmake where to look?

273K
  • 29,503
  • 10
  • 41
  • 64
  • Thank you for your answer. I linked the pcap c library, because pcpp has a dependency to that. When compiling without the pcap linking I get more errors like in function `pcpp::PcapLiveDevice::captureThreadMain(void*)': PcapLiveDevice.cpp:208: undefined reference to `pcap_dispatch' I didn't use any "FindPcap++" because as I said I'm using a custom version of pcap++ – bemerged Jun 07 '20 at 20:34
  • I tried linking to the pcap++ libraries in the target_link_libraries part I also included that headers with include_directories("${CMAKE_SOURCE_DIR}/../Pcap++/header/") include_directories("${CMAKE_SOURCE_DIR}/../Packet++/header/") include_directories("${CMAKE_SOURCE_DIR}/../Common++/header/") – bemerged Jun 07 '20 at 20:36
  • You are completely misunderstanding what I said. – 273K Jun 07 '20 at 20:37
  • Can you maybe tell me what you said then? :) – bemerged Jun 07 '20 at 20:39
0

try this link order

-lPcap++ -lPacket++ -lCommon++ -lpcap