如何使用 cmake 正确编译我的 c 项目所依赖的 libpcap?

问题描述 投票:0回答:0

我正在使用 cmake 编译 libpcap。 libpcap 将链接到我的应用程序。这是我的 CMakeLists.txt 文件的一部分:

include(FetchContent)

FetchContent_Declare(
        pcap
        GIT_REPOSITORY https://github.com/the-tcpdump-group/libpcap.git
        GIT_TAG libpcap-1.10.1
        SOURCE_DIR ${PROJECT_SOURCE_DIR}/ext/pcap
)
FetchContent_MakeAvailable(pcap)

当我在 CLion 中单击构建按钮时。发生错误:

-- Checking C compiler flag -std=gnu99
-- Use DYNAMIC runtime
-- Support IPv6
-- Checking sanitizer OFF
CMake Error at ext/pcap/CMakeLists.txt:1030 (message):
  OFF isn't a supported sanitizer

ext/pcap/CMakeLists.txt:1030
周围的内容是:

set(SANITIZER_FLAGS "")
foreach(sanitizer IN LISTS ENABLE_SANITIZERS)
    # Set -Werror to catch "argument unused during compilation" warnings

    message(STATUS "Checking sanitizer ${sanitizer}")
    set(sanitizer_variable "sanitize_${sanitizer}")
    set(CMAKE_REQUIRED_FLAGS "-Werror -fsanitize=${sanitizer}")
    check_c_compiler_flag("-fsanitize=${sanitizer}" ${sanitizer_variable})
    if(${${sanitizer_variable}})
        set(SANITIZER_FLAGS "${SANITIZER_FLAGS} -fsanitize=${sanitizer}")
        message(STATUS "${sanitizer} sanitizer supported using -fsanitizer=${sanitizer}")
    else()
        #
        # Try the versions supported prior to Clang 3.2.
        # If the sanitizer is "address", try -fsanitize-address.
        # If it's "undefined", try -fcatch-undefined-behavior.
        # Otherwise, give up.
        #
        set(sanitizer_variable "OLD_${sanitizer_variable}")
        if ("${sanitizer}" STREQUAL "address")
            set(CMAKE_REQUIRED_FLAGS "-Werror -fsanitize-address")
            check_c_compiler_flag("-fsanitize-address" ${sanitizer_variable})
            if(${${sanitizer_variable}})
                set(SANITIZER_FLAGS "${SANITIZER_FLAGS} -fsanitize-address")
                message(STATUS "${sanitizer} sanitizer supported using -fsanitize-address")
            else()
                message(FATAL_ERROR "${sanitizer} isn't a supported sanitizer")
            endif()
        elseif("${sanitizer}" STREQUAL "undefined")
            set(CMAKE_REQUIRED_FLAGS "-Werror -fcatch-undefined-behavior")
            check_c_compiler_flag("-fcatch-undefined-behavior" ${sanitizer_variable})
            if(${${sanitizer_variable}})
                set(SANITIZER_FLAGS "${SANITIZER_FLAGS} -fcatch-undefined-behavior")
                message(STATUS "${sanitizer} sanitizer supported using catch-undefined-behavior")
            else()
                message(FATAL_ERROR "${sanitizer} isn't a supported sanitizer")
            endif()
        else()
            message(FATAL_ERROR "${sanitizer} isn't a supported sanitizer")
        endif()
    endif()

    unset(CMAKE_REQUIRED_FLAGS)
endforeach()

那么,我该如何解决这个问题来构建我的项目?

其实我也不知道怎么处理。第一次用cmake...

c cmake compiler-errors cross-compiling libpcap
© www.soinside.com 2019 - 2024. All rights reserved.