1.
libcurl引入的时候必须要加载下面三个库
#pragma comment(lib, "ws2_32.lib") #pragma comment(lib, "wldap32.lib") #pragma comment(lib, "crypt32.lib" )
32位程序需要引入前两个,64位程序需要引入这三个
然后要在property pages->c/c++->preprocessor->preprocessor definitions中添加CURL_STATICLIB
不然会报下面的错误
error LNK2001: unresolved external symbol __imp_curl_easy_perform
error LNK2001: unresolved external symbol __imp_curl_global_init
error LNK2001: unresolved external symbol __imp_curl_global_cleanup
error LNK2001: unresolved external symbol __imp_curl_easy_init
error LNK2001: unresolved external symbol __imp_curl_easy_cleanup
error LNK2001: unresolved external symbol __imp_curl_easy_setopt
2.
fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Configuration Properties->C/C++->Precompiled Headers->Precompiled Header->Not Using Precompiled Headers
3.
#pragma comment(lib, "shlwapi.lib")
后面必须跟lib名字,不可以加路径,如果要指定路径,那就在工程中配置对应lib的引用路径
4.
网络编程中如果出现
error C2011: 'sockaddr' : 'struct' type redefinition
类似的编译错误,原因就是因为在#include <WinSock2.h>前面包含了#include <Windows.h>
因为#include <Windows.h>中包含了#include <winsock.h>,而#include <winsock.h>中定义了与#include <WinSock2.h>一样名字的类型。现在都是#include <WinSock2.h>,#include <winsock.h>是比较老的功能了。名字一样但是里面的结构可能有区别,就导致报错。修改方法就是查看所有工程中引用#include <Windows.h>和#include <WinSock2.h>的地方,确保#include <WinSock2.h>在#include <Windows.h>前面。不仅仅是直接引用,也包括间接引用,比如你在引用#include <WinSock2.h>之前引用了其他头文件,其他头文件中引用了#include <Windows.h>,这样也是会报错
也可以在所有的引用最前面或是所有#include <Windows.h>前面定义#define _WINSOCKAPI_,因为在#include <winsock.h>通过#define _WINSOCKAPI_来判断是否引用这个头文件,所以可以提前定义让它不引用就可以了
5.
如果使用#define _WINSOCKAPI_来解决上面的问题,那么有可能导致curl的编译错误
<path to curl source>curlincludecurlcurl.h(134,29): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path to curl source>curlincludecurlcurl.h(134,16): error C2146: syntax error: missing ';' before identifier 'curl_socket_t'
<path to curl source>curlincludecurlcurl.h(397,52): error C2061: syntax error: identifier 'curl_socket_t'
<path to curl source>curlincludecurlcurl.h(407,23): error C2079: 'curl_sockaddr::addr' uses undefined struct 'sockaddr'
<path to curl source>curlincludecurlcurl.h(411,3): error C2065: 'curl_opensocket_callback': undeclared identifier
<path to curl source>curlincludecurlcurl.h(411,27): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<path to curl source>curlincludecurlcurl.h(411,27): error C2378: 'curl_socket_t': redefinition; symbol cannot be overloaded with a typedef
<path to curl source>curlincludecurlcurl.h(134): message : see declaration of 'curl_socket_t'
<path to curl source>curlincludecurlcurl.h(411,28): error C2513: 'int': no variable declared before '='
<path to curl source>curlincludecurlcurl.h(411,28): error C2143: syntax error: missing ';' before '('
<path to curl source>curlincludecurlcurl.h(411,34): error C2062: type 'void' unexpected
<path to curl source>curlincludecurlcurl.h(416,59): error C2061: syntax error: identifier 'curl_socket_t'
<path to curl source>curlincludecurlmulti.