使用Catalina C ++的卷曲失败,并得到“体系结构x86_64的未定义符号”

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

我正在尝试使用Catalina 10.15运行示例c ++程序:

#include </usr/local/opt/curl/include/curl/curl.h>

int main(void) {

    CURL* curl;
    CURLcode result;

    curl = curl_easy_init();
    curl_easy_setopt(curl, CURLOPT_URL, "https://www.wikipedia.org");

    result = curl_easy_perform(curl);

    curl_easy_cleanup(curl);

    return 0;
}

我已安装curl与:

brew install curl

我不明白为什么这不起作用,我得到了:

Scanning dependencies of target 2700
[ 50%] Building CXX object CMakeFiles/2700.dir/main.cpp.o
[100%] Linking CXX executable 2700
Undefined symbols for architecture x86_64:
  "_curl_easy_cleanup", referenced from:
      _main in main.cpp.o
  "_curl_easy_init", referenced from:
      _main in main.cpp.o
  "_curl_easy_perform", referenced from:
      _main in main.cpp.o
  "_curl_easy_setopt", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [2700] Error 1
make[2]: *** [CMakeFiles/2700.dir/all] Error 2
make[1]: *** [CMakeFiles/2700.dir/rule] Error 2
make: *** [2700] Error 2

我的CMakeLists.txt如下:

cmake_minimum_required(VERSION 3.15.3)
project(2700)

include_directories(/usr/local/opt/curl/include/)

set(CMAKE_CXX_STANDARD 17)

add_executable(2700 main.cpp )

我正在使用CLion,对C ++还是相当陌生,尤其是在MacOS上。

我该怎么办才能使卷发正常工作,而不会出现问题?

c++ macos curl libcurl
1个回答
0
投票

我已经意识到我需要在CMakeLists.txt中进行链接:

此作品:

cmake_minimum_required(VERSION 3.15.3)
project(2700)

include_directories(/usr/local/opt/curl/include/)

set(CMAKE_CXX_STANDARD 17)

set(CURL_LIBRARY "-lcurl")
find_package(CURL REQUIRED)

add_executable(2700 main.cpp )

include_directories(${CURL_INCLUDE_DIR})
target_link_libraries(2700 ${CURL_LIBRARIES})
© www.soinside.com 2019 - 2024. All rights reserved.