-2

Can someone explain me how to install libpcap? I downloaded libpcap-1.9.1 from official site (tcpdump). There are a lot of files and i cant understand what to do. i tried:

project(test)
set(CMAKE_CXX_STANDARD 14)
include_directories(libpcap-1.9.1)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/libpcap-1.9.1/cmake/Modules")
find_package(Packet REQUIRED)
add_executable(${PROJECT_NAME} main.cpp )
target_link_libraries(${PROJECT_NAME} ${PACKET_LIBRARY})

But it doesnt work

Qada
  • 109
  • 6

1 Answers1

0

Just use add_subdirectory() with target_link_libraries():

project(test)

set(CMAKE_CXX_STANDARD 14)

include_directories(libpcap-1.9.1)

add_subdirectory(libpcap-1.9.1)

add_executable(${PROJECT_NAME} main.cpp )

target_link_libraries(${PROJECT_NAME} PRIVATE pcap)
Waqar
  • 6,944
  • 2
  • 26
  • 39
  • i tried this and it give me another error "CMake Error at libpcap-1.9.1/CMakeLists.txt:412 (message): getaddrinfo is required, but wasn't found" but i think the problem is in the library itself. – Qada May 31 '20 at 17:13
  • are you using `mingw`? – Waqar May 31 '20 at 17:17
  • I suspect it's because of this: https://stackoverflow.com/questions/12765743/implicit-declaration-of-function-getaddrinfo-on-mingw – Waqar May 31 '20 at 17:23
  • can you try adding the definition using: `target_compile_definitions(pcap PUBLIC _WIN32_WINNT=0x501)` before linking. It may solve the issue – Waqar May 31 '20 at 17:25
  • or `add_definitions(-D_WIN32_WINNT=0x600)`, – Waqar May 31 '20 at 17:27
  • It is already specified here: https://github.com/the-tcpdump-group/libpcap/blob/f87b39e9b6fed60e28c7df050a5dfeb2f6f22abb/CMakeLists.txt#L152 so I am not sure what the actual problem might be. – Waqar May 31 '20 at 17:32