我正在尝试了解cURL并在线发现了一些我想在Visual Studio中编译的代码,但是我得到了一系列奇怪的错误。我尝试使用谷歌搜索错误但找不到与我的问题相关的任何内容。我安装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 ==========
可能是什么问题?
编辑: 程序没有错误:
#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 :(得分:11)
错误是您正在将C ++代码编译为C.将文件名更改为main.cpp。
答案 1 :(得分:0)
你试过包括math.h吗? 我使用Visual Studio 2012,我可以使用浮动函数。