Libcurl Open Source Library in VS2010 environment to compile and install, configuration detailed
Transferred from: http://my.oschina.net/u/1420791/blog/198247
Curl Open Source Library VS2010 environment compiled installation, configuration detailed
A preparation
1.1 Curl Official Website: http://curl.haxx.se/download.html
1.2 Find the source package, I download here is 7.32.0 version: Http://curl.haxx.se/download/curl-7.32.0.zip
Two steps
2.1
Open curl-7.32.0\vs\vc8\lib\vc8libcurl.vcproj file, vs will Prompt for upgrade 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 mean
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", change it
into "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.
2.5. Remove the "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 (/MT)
Libcurl.dll//release multi-threaded Debug (/MTD)
The above is the static library version, generating EXE volume, including the library.
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 then put it in your own create a debug and a release folder,
For example Debug/libcurl.lib release//libcurl.lib
Debug/libcurl.dll Release//libcurl.dll
Note put it in the C:\curl-7.32.0\curl-7.32.0\lib\ directory
(Can be customized, just pay attention to the variables that are included in the library later)
2.8 Creating two environment variables
For example, Curl_inc is set to C:\curl-7.32.0\curl-7.32.0\include
For example, Curl_lib is set to C:\curl-7.32.0\curl-7.32.0\lib
Three-result test
3.1 Then start testing how to use it.
To test the Lib file, create a new console program,
Open Project Properties > C\c++ > General > Include header file $ (curl_inc)
Open Project Properties > C\c++ > General > Include library file $ (curl_lib) \debug
(Note that debug and release are different here, so as not to affect post-project commissioning)
3.2
Open Project Properties > c\c++ > Preprocessor > Preprocessor definition. Add "Curl_staticlib".
In this way, those interface functions are not declared as export functions.
3.3 Adding dependent library files
3.4 Find a self-brought example test/docs/examples/simple.c source file
[CPP] view Plaincopyprint?
#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_followlocation, 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
Libcurl Open Source Library in VS2010 environment to compile and install, configuration detailed