[Libcurl]Build&Use Manual

gaearrow發表於2017-11-24

Version

  • Visual Studio 2013
  • curl-7.53.1.zip(download

Build libcurl static library

1 Extract curl-7.53.1.zip to a local directory(c:\libcurl)
2 Open VS2013 x86 Native Tools Command Prompt
3 cd c:\libcurl\winbuild
4 Compile

/MD
nmake /f Makefile.vc mode=static VC=12
/MT
nmake /f Makefile.vc mode=static VC=12 RTLIBCFG=static

Static linking of Microsoft’s C RunTime (CRT)
If you are using mode=static nmake will create and link to the static build of
libcurl but not the static CRT. If you must you can force nmake to link in
the static CRT by passing RTLIBCFG=static. Typically you shouldn’t use that
option, and nmake will default to the DLL CRT. RTLIBCFG is rarely used and
therefore rarely tested. When passing RTLIBCFG for a configuration that was
already built but not with that option, or if the option was specified
differently, you must destroy the build directory containing the configuration
so that nmake can build it from scratch.

5 Build result in C:\libcurl\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl

1 cd C:\libcurl\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl
2 copy include&lib directories to your solutions directory
3 Configuration Properties > C/C++ > General > Additional Include Directories: add * $(SolutionDir)\include\ *
4 Configuration Properties > C/C++ > Preprocessor > Preprocessor Definitions: add CURL_STATICLIB
5 Configuration Properties > Linker > General > Additional Library Directories: add * $(SolutionDir)\lib\ *
6 Configuration Properties > Linker > Input > Additional Dependencies: add libcurl_a.lib

Test libcurl in Your Project

#include <stdio.h>
#include <curl/curl.h>

int main(int argc, char* argv[])
{
    CURL *curl = curl_easy_init();
    if (curl) printf("curl_easy_init() succeeded!\n"); 
    else fprintf(stderr, "Error calling curl_easy_init().\n");
    return 0;
}

Refer

相關文章