2013-07-10 3 views
0

Мне нужно написать код C++ для загрузки веб-страницы, я знаю, что мне нужно завивать, im используя Mac osx, поэтому у меня есть libcurl в/usr/include/curl. когда я скомпилировать этот код, я получаю эту ошибку:C++ с curl using netbeans

#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) 

ответ

1

Вы должны добавить curl библиотеки в настройках проекта: Свойства проекта - Build - Linker. Кажется, вы добавили путь к заголовкам, но вам также нужно добавить библиотеку, которая будет связана после этапа компиляции.

1

в дополнение @ sasha.sochka Ответим

screenshot of Project Build Properties