2013-09-14 2 views
3

Я пытаюсь узнать о cURL и нашел код в Интернете, который я хотел скомпилировать в Visual Studio, но я получаю ряд странных ошибок. Я пробовал поиск ошибок, но не смог найти ничего, что связано с моей проблемой. Я установил библиотеки CURL в порядке, но когда я пытаюсь запустить эту программу:Ошибка C2061: синтаксическая ошибка: идентификатор «acosf» при использовании cURL

#include <curl/curl.h> 
#include <fstream> 
#include <sstream> 
#include <iostream> 

// callback function writes data to a std::ostream 
static size_t data_write(void* buf, size_t size, size_t nmemb, void* userp) 
{ 
    if(userp) 
    { 
     std::ostream& os = *static_cast<std::ostream*>(userp); 
     std::streamsize len = size * nmemb; 
     if(os.write(static_cast<char*>(buf), len)) 
      return len; 
    } 

    return 0; 
} 

/** 
* timeout is in seconds 
**/ 
CURLcode curl_read(const std::string& url, std::ostream& os, long timeout = 30) 
{ 
    CURLcode code(CURLE_FAILED_INIT); 
    CURL* curl = curl_easy_init(); 

    if(curl) 
    { 
     if(CURLE_OK == (code = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &data_write)) 
     && CURLE_OK == (code = curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L)) 
     && CURLE_OK == (code = curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L)) 
     && CURLE_OK == (code = curl_easy_setopt(curl, CURLOPT_FILE, &os)) 
     && CURLE_OK == (code = curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout)) 
     && CURLE_OK == (code = curl_easy_setopt(curl, CURLOPT_URL, url.c_str()))) 
     { 
      code = curl_easy_perform(curl); 
     } 
     curl_easy_cleanup(curl); 
    } 
    return code; 
} 

int main() 
{ 
    curl_global_init(CURL_GLOBAL_ALL); 

    std::ofstream ofs("output.html"); 
    if(CURLE_OK == curl_read("http://google.com", ofs)) 
    { 
     // Web page successfully written to file 
    } 

    std::ostringstream oss; 
    if(CURLE_OK == curl_read("http://google.com", oss)) 
    { 
     // Web page successfully written to string 
     std::string html = oss.str(); 
    } 

    if(CURLE_OK == curl_read("http://google.com", std::cout)) 
    { 
     // Web page successfully written to standard output (console?) 
    } 

    curl_global_cleanup(); 
} 

я получаю следующий список ошибок:

1>------ Build started: Project: cURL.c, Configuration: Debug Win32 ------ 
1> main.c 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xtgmath.h(111): warning C4602: #pragma pop_macro : 'new' no previous #pragma push_macro for this identifier 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xtgmath.h(112): warning C4193: #pragma warning(pop) : no matching '#pragma warning(push)' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xtgmath.h(113): warning C4161: #pragma pack(pop...) : more pops than pushes 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(28): error C2061: syntax error : identifier 'acosf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(28): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(28): error C2061: syntax error : identifier 'asinf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(29): error C2061: syntax error : identifier 'atanf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(29): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(29): error C2061: syntax error : identifier 'atan2f' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(29): error C2061: syntax error : identifier 'ceilf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(30): error C2061: syntax error : identifier 'cosf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(30): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(30): error C2061: syntax error : identifier 'coshf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(30): error C2061: syntax error : identifier 'expf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(31): error C2061: syntax error : identifier 'fabsf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(31): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(31): error C2061: syntax error : identifier 'floorf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(31): error C2061: syntax error : identifier 'fmodf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(32): error C2061: syntax error : identifier 'frexpf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(32): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(32): error C2061: syntax error : identifier 'ldexpf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(32): error C2061: syntax error : identifier 'logf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(33): error C2061: syntax error : identifier 'log10f' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(33): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(33): error C2061: syntax error : identifier 'modff' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(33): error C2061: syntax error : identifier 'powf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(34): error C2061: syntax error : identifier 'sinf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(34): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(34): error C2061: syntax error : identifier 'sinhf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(34): error C2061: syntax error : identifier 'sqrtf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(35): error C2061: syntax error : identifier 'tanf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(35): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(35): error C2061: syntax error : identifier 'tanhf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(37): error C2061: syntax error : identifier 'acosl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(37): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(37): error C2061: syntax error : identifier 'asinl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(38): error C2061: syntax error : identifier 'atanl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(38): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(38): error C2061: syntax error : identifier 'atan2l' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(38): error C2061: syntax error : identifier 'ceill' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(39): error C2061: syntax error : identifier 'cosl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(39): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(39): error C2061: syntax error : identifier 'coshl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(39): error C2061: syntax error : identifier 'expl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(40): error C2061: syntax error : identifier 'fabsl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(40): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(40): error C2061: syntax error : identifier 'floorl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(40): error C2061: syntax error : identifier 'fmodl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(41): error C2061: syntax error : identifier 'frexpl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(41): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(41): error C2061: syntax error : identifier 'ldexpl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(41): error C2061: syntax error : identifier 'logl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(42): error C2061: syntax error : identifier 'log10l' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(42): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(42): error C2061: syntax error : identifier 'modfl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(42): error C2061: syntax error : identifier 'powl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(43): error C2061: syntax error : identifier 'sinl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(43): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(43): error C2061: syntax error : identifier 'sinhl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(43): error C2061: syntax error : identifier 'sqrtl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(44): error C2061: syntax error : identifier 'tanl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(44): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(44): error C2061: syntax error : identifier 'tanhl' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(46): error C2061: syntax error : identifier 'abs' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(46): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(48): error C2061: syntax error : identifier 'acos' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(48): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(48): error C2061: syntax error : identifier 'asin' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(49): error C2061: syntax error : identifier 'atan' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(49): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(49): error C2061: syntax error : identifier 'atan2' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(49): error C2061: syntax error : identifier 'ceil' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(50): error C2061: syntax error : identifier 'cos' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(50): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(50): error C2061: syntax error : identifier 'cosh' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(50): error C2061: syntax error : identifier 'exp' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(51): error C2061: syntax error : identifier 'fabs' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(51): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(51): error C2061: syntax error : identifier 'floor' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(51): error C2061: syntax error : identifier 'fmod' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(52): error C2061: syntax error : identifier 'frexp' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(52): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(52): error C2061: syntax error : identifier 'ldexp' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(52): error C2061: syntax error : identifier 'log' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(53): error C2061: syntax error : identifier 'log10' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(53): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(53): error C2061: syntax error : identifier 'modf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(53): error C2061: syntax error : identifier 'pow' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(54): error C2061: syntax error : identifier 'sin' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(54): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(54): error C2061: syntax error : identifier 'sinh' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(54): error C2061: syntax error : identifier 'sqrt' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(55): error C2061: syntax error : identifier 'tan' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(55): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(55): error C2061: syntax error : identifier 'tanh' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(57): error C2061: syntax error : identifier 'hypot' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(57): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cmath(57): error C2061: syntax error : identifier 'hypotf' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cstdio(36): error C2054: expected '(' to follow 'using' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cstdio(38): error C2061: syntax error : identifier 'using' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cstdio(38): error C2054: expected '(' to follow 'using' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cstdio(39): error C2061: syntax error : identifier 'clearerr' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cstdio(39): error C2059: syntax error : ';' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cstdio(39): error C2061: syntax error : identifier 'fclose' 
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\cstdio(39): fatal error C1003: error count exceeds 100; stopping compilation 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

Что может быть проблема?

EDIT: Программа без ошибок:

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

int main(void) 
{ 
    CURL *curl; 
    CURLcode res; 

    curl = curl_easy_init(); 
    if(curl) { 
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.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; 
} 
+0

Ваша библиотека cURL пытается использовать функции C99 'float', которые не предоставляются библиотекой времени выполнения вашего компилятора. C89 определяет 'acos()'; C99 определяет 'acosf()' и 'acosl()' тоже, но у вас их нет у вас. Вам нужно будет узнать, как скомпилировать cURL, чтобы он не ожидал использовать эти функции, или вам придется их написать: float acosf (float x) {return acos (x); } Промыть и повторить - объявить тошноту. Затем вам нужно будет исправить вашу линию ссылок, чтобы забрать свои функции после того, как библиотека cURL была связана. (Комментарий добавлен, удален, читается ...) –

+0

Извините, что сбив с толку, комментируя, отвечая, а затем решая решения на вас. Виноват! Вы спрашиваете: «Есть ли способ включить эти функции, чтобы компилятор мог их видеть? Не могу ли я загрузить их где-нибудь?» - Разумный вопрос: я не знаю, откуда их скачать. Я не совсем уверен, что происходит, поближе. У вас есть синтаксические ошибки, когда я диагностировал ошибки времени ссылки, поэтому проблема не совсем в том, что я думал. Тем не менее, MSVC является компилятором C89, а не компилятором C99 или C11, поэтому он связан с проблемой, о которой я говорил, но не совсем так, как я сказал. –

+0

@JonathanLeffler Нет проблем, я думаю, я заслуживаю эту головную боль для использования Windows на первом месте. Я просто не могу поверить, что Microsoft не будет поддерживать что-то столь же важное, как это. – Urler

ответ

11

Ошибка в том, что вы компилируете код на C++ как C. Измените имя файла на main.cpp.

0

Вы пробовали в том числе math.h? Я использую Visual Studio 2012, и я могу использовать функции float.

+0

Это должен быть комментарий, а не ответ. – john

+0

@ C0dR Да, я пробовал это, но ошибки все еще были. – Urler

Смежные вопросы