简体   繁体   English

使用netbeans卷曲的C ++

[英]C++ with curl using netbeans

I need to write C++ code to download webpage, I know that I need curl, im using Mac osx so I have the libcurl in /usr/include/curl. 我需要编写C ++代码来下载网页,我知道我需要curl,即时通讯使用Mac osx所以我在/ usr / include / curl中有libcurl。 when I compile this code I get this error : 当我编译此代码时,我收到此错误:

#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;
}

Here is the error: 这是错误:

  "/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)

You should add curl library in project settings: Project Properties - Build - Linker. 您应该在项目设置中添加curl库:项目属性 - 构建 - 链接器。 It seems you added a path to headers but you also need to add a library which will be linked after the compilation stage. 您似乎添加了一个标题路径,但您还需要添加一个将在编译阶段后链接的库。

to complement @sasha.sochka's answer 补充@ sasha.sochka的答案

Project Build Properties的截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM