Libcurl Open Source Library in VS2010 environment to compile and install, configuration detailed

Source: Internet
Author: User

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?

  1. #include "stdafx.h"

  2. #include <stdio.h>

  3. #include <curl/curl.h>

  4. #pragma comment (lib, "Libcurl.lib")

  5. int _tmain (int argc, _tchar* argv[])

  6. {

  7. CURL *curl;

  8. Curlcode Res;

  9. Curl = Curl_easy_init ();

  10. if (Curl) {

  11. Curl_easy_setopt (Curl, Curlopt_url, "http://www.baidu.com");

  12. /* example.com is redirected, so we are libcurl to follow redirection */

  13. Curl_easy_setopt (Curl, curlopt_followlocation, 1L);

  14. /* Perform the request, res'll get the return code */

  15. res = curl_easy_perform (curl);

  16. /* Check for errors */

  17. if (res! = CURLE_OK)

  18. fprintf (stderr, "Curl_easy_perform () failed:%s\n",

  19. Curl_easy_strerror (res));

  20. /* Always cleanup */

  21. Curl_easy_cleanup (curl);

  22. }

  23. return 0;

  24. }



3.5 Example Test Results

Libcurl Open Source Library in VS2010 environment to compile and install, configuration detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.