gpt4 book ai didi

使用 netbeans 的 C++ 和 curl

转载 作者:行者123 更新时间:2023-11-28 03:13:50 25 4
gpt4 key购买 nike

我需要编写 C++ 代码来下载网页,我知道我需要 curl,我使用的是 Mac osx,所以我在/usr/include/curl 中有 libcurl。当我编译这段代码时,我得到了这个错误:

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* example.com is redirected, so we tell libcurl to follow redirection */
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));

/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}

这里是错误:

  "/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
rm -f -r build/Debug
rm -f dist/Debug/GNU-MacOSX/cppapplication

CLEAN SUCCESSFUL (total time: 54ms)
Undefined symbols for architecture x86_64:
"_curl_easy_cleanup", referenced from: _main in main.o
"_curl_easy_init", referenced from: _main in main.o
"_curl_easy_perform", referenced from: _main in main.o
"_curl_easy_setopt", referenced from: _main in main.o
"_curl_global_cleanup", referenced from: _main in main.o
"_curl_global_init", referenced from: _main in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-MacOSX/cppapplication] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 264ms)

最佳答案

您应该在项目设置中添加 curl 库:项目属性 - 构建 - 链接器。似乎您添加了标题的路径,但您还需要添加一个将在编译阶段后链接的库。

关于使用 netbeans 的 C++ 和 curl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17582198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com