a preparation
1.1 Curl official Website Download address: http://curl.haxx.se/download.html
1.2 Find the source package, the latest version of the official website is 7. 0, but the curl-7.54.0\projects\windows path of this compression package Vc6-vc14 each version of the VS solution, but after opening the compilation will prompt for the OpenSSL related header file:
Fatal error C1083: Could not open include file: "Openssl/ssl.h": No such files or directory
It should be a new support for SSL, used to OpenSSL, and OpenSSL needs to be installed manually. There are two ways to configure OpenSSL, one is to install the download installation package directly (as with the WINDOWSSDK package), and to download the OpenSSL code to compile the configuration. Of course the former is the simplest, OpenSSL installation configuration see: Windows under OpenSSL download installation and use of http://www.cnblogs.com/lpxblog/p/5382653.html.
because to implement the Send mail function, the sample code downloaded on the Internet is basically impossible to use, especially the network processing this piece, the mail will often fail to send. Because time is tight, to grasp and test the effect, so there is no time to configure the installation of OpenSSL and compile a new version of Libcurl. Just see the relevant article, learned that 7.32.0 version can be directly used to compile with VS2010, so to the official website to download 7.32.0 version, the specific access to the old version of the entry is as follows:
originally because of the small project at hand, with the keyword curl to the project directory search, see before the project there is no Libcurl library project, can be directly compiled, and then the compiled library to come directly to use, but compiled to get our project run, the results curl_ Easy_perform interface call failed, return curle_unsupported_protocol error code, is the current library does not support the SMTP protocol. I don't think so, SMTP is officially supported. Look at the code only to find that before someone used CURL_DISABLE_SMTP and http_only macros to the SMTP, FTP, Telnet and other unused protocols are cropped, only the main HTTP features are retained, c files are removed from the project, but there is still some on the disk. Then try to add the SMTP protocol functions, such as the Disable macro comment out, compile Libcurl, the link is not linked to the interface of the SMTP module. It was later found that SMTP.C was not added to the project, i.e. SMTP.C was not compiled, so the interface to the SMTP module was not linked. But add in after compile still have a problem, back and forth tried several times or not, so had to go to official web download new version of Libcurl, search Libcurl compiler configuration method, can only use the official code to compile the library file.
previously saw the project Mupdf module also used to curl code, but is also cut, the function is basically deleted, the SMTP mail sending module must have been deleted, but also can not be used.
two steps
2.1 Open Curl-7.32.0\vs\vc8\lib\vc8libcurl.vcproj file, VS2010 will be prompted to upgrade the project, next.
VC Project Some Setup problems can not be directly compiled, need to make a minor modification
2.2 Open Project Properties > C\c++ > General > Additional Include directories. The Include directory here is ". \include ", and this directory does not exist at all, it should point to" Curl-7.32.0\include "is right, so change this to". \.. \.. \include ". (or direct full path is possible)
2.3 Open Project Properties > c\c++ > Preprocessor > Preprocessor definition. Here is a default macro "Building_libcurl", if you want to compile a static library, you want to change it to "Curl_staticlib". In this way, those interface functions are not declared as export functions.
2.4 Open Project Properties > c\c++ > Library Manager > General > Additional Dependencies. Add Ws2_32.lib and Wldap32.lib, which curl must rely on. Or use #pragma comment precompiled directives in your code to manually introduce these two LIB libraries.
2.5. Remove "libcurl.rc" from the project, it is only the version information, will only increase the file, remove. Matter
2.6 Can compile the following version, manually set the compilation as needed
Libcurld.lib//debug multi-threaded Debug (/MTD)
Libcurl.lib//release multi-threaded (/MT)
The above is a 32-bit static library version, generating EXE volume large, including libraries.
Two versions are available. However, when using the connection, pay attention to the corresponding version.
Libcurld.lib//debug multi-threaded DLL debug (/MDD)
Libcurl.dll//release multi-threaded DLL (MD)
The above is the dynamic library version, the Generation EXE volume is small, does not contain the library.
2.7 If your project is 64-bit and you are using a static library of curl, you also need to compile the static library of Crul into 64-bit. The compilation method is simple, create a new platform x64, and inherit the configuration items directly from the Win32 corresponding configuration items.
Three-result test
3.1 Then start testing how to use it.
To test the Lib file, create a new console program, copy the Include folder under Curl and the static library you just generated to the current project directory, and set the include path and dependent library path. (Note that debug and release are different here, so as not to affect post-project commissioning)
3.2 The default is the dynamic library, and if you are compiling to a static library, open the project properties > c\c++ > Preprocessor > Preprocessor definition. Add "Curl_staticlib".
3.3 Adding dependent library files: Ws2_32.lib and wldap32.lib, this library is required by Libcurl.
3.4 Find a self-brought example test/docs/examples/simple.c source file
#include "stdafx.h"
#include <stdio.h>
#include <curl/curl.h>
#pragma comment (lib, " Libcurl.lib ")
int _tmain (int argc, _tchar* argv[])
{
CURL *curl;
Curlcode Res;
Curl = Curl_easy_init ();
if (Curl) {
curl_easy_setopt (curl, Curlopt_url, "http://www.baidu.com");
/* example.com is redirected, so we are libcurl to follow redirection *
/curl_easy_setopt (Curl, Curlopt_followlocati On, 1L);
/* Perform the request, res'll 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;
}
3.5 Example Test Results
PS: In fact, this article can not be considered original, but also on the basis of others to add their own problems encountered, modified.