Compiling and using libcurl.lib static libraries under Windows

Source: Internet
Author: User
Tags curl

1. Download the latest version of Libcurl, mine is curl-7.44.0.zip, decompression, into the directory winbuild, read BUILD.WINDOWS.txt this document

Open the VS2013 Developer command Prompt and execute nmake/f makefile.vc mode=static vc=12

After compiling the Libcurl Static library will appear in the Builds directory including header files and libcurl_a.lib, what we need is builds/ Libcurl-vc12-x86-release-static-ipv6-sspi-winssl the Include and Lib two folders below

A paragraph in the document.

Static linking of Microsoft ' s C RunTime (CRT):
==============================================
If you are are using mode=static nmake Create and link to the static build of
Libcurl but *not* the static CRT. If You must your can force NMAKE to link in
The static CRT by passing rtlibcfg=static. Typically you shouldn ' t with that
option, and NMAKE would default to the DLL CRT. Rtlibcfg is rarely used and
Therefore rarely tested. When passing rtlibcfg for a configuration this was
Already built but not with that option, or if the option is specified
Differently, you are must destroy the build directory containing the configuration
So, NMAKE can build it from scratch.

VS Generate Code There is a runtime option (Project Properties-Configuration Properties-C + +-code generation-Run-time Library)/MT and/MD (/MTD and/MDD are the corresponding versions of debug)

That is, if you compile with rtlibcfg=static this option, it is equivalent to compiling the/MT version of the Libcurl, otherwise it is/MD version of the


2. Open VS2013 New Project Select Win32 Console application, additional options to select an empty item

Then copy the previously compiled header folder and Lib folder to the path where the project is located. Project right Add-existing item, put Libcurl_a.lib into project

Create a new CPP file and test if you can use

#include "include/curl/curl.h"

int main ()
{
	curl_easy_init ();
	return 0;
}
Error:

Error LNK2019: unresolved external symbol __imp__curl_easy_init, which is referenced in function _main

Fatal error Lnk1120:1 an unresolved external command

Libcurl is not linked to the program and cannot find this function entry

Solution: Open the Project properties, configuration Properties-C + +-preprocessor-preprocessor definitions-open drop-down box-edit-text box input Curl_staticlib-Save (or #define CURL_STATICLIB in curl.h)

Re-compiling

Error:

1>libcmt.lib (invarg.obj): Error LNK2005: __invoke_watson already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (lseeki64.obj): Error LNK2005: __lseeki64 already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (dosmap.obj): Error LNK2005: __errno already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (tolower.obj): Error LNK2005: _tolower already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (wsetloca.obj): Error LNK2005: __configthreadlocale already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (crt0dat.obj): Error LNK2005: __amsg_exit already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (crt0dat.obj): Error LNK2005: __cexit already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (crt0dat.obj): Error LNK2005: __exit already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (crt0dat.obj): Error LNK2005: __initterm_e already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (crt0dat.obj): Error LNK2005: _exit already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (mlock.obj): Error LNK2005: __lock already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (mlock.obj): Error LNK2005: __unlock already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (winapisupp.obj): Error LNK2005: ___crtsetunhandledexceptionfilter already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (winapisupp.obj): Error LNK2005: ___crtterminateprocess already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (winapisupp.obj): Error LNK2005: ___crtunhandledexception already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (_file.obj): Error LNK2005: ___iob_func already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (winxfltr.obj): Error LNK2005: __xcptfilter already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (hooks.obj): Error LNK2005: "Void __cdecl terminate (? terminate@ @YAXXZ) is already in MSVCRTD.lib ( MSVCR120D.dll) defined in
1>libcmt.lib (crt0init.obj): Error LNK2005: ___xi_a already defined in MSVCRTD.lib (cinitexe.obj)
1>libcmt.lib (crt0init.obj): Error LNK2005: ___xi_z already defined in MSVCRTD.lib (cinitexe.obj)
1>libcmt.lib (crt0init.obj): Error LNK2005: ___xc_a already defined in MSVCRTD.lib (cinitexe.obj)
1>libcmt.lib (crt0init.obj): Error LNK2005: ___xc_z already defined in MSVCRTD.lib (cinitexe.obj)
1>libcmt.lib (errmode.obj): Error LNK2005: ___set_app_type already defined in MSVCRTD.lib (MSVCR120D.dll)
1>libcmt.lib (fflush.obj): Error LNK2005: _fflush already defined in MSVCRTD.lib (MSVCR120D.dll)
1>link:warning LNK4098: Default Library "MSVCRTD" conflicts with other libraries; please use/nodefaultlib:library
1>link:warning LNK4098: Default Library "LIBCMT" conflicts with other libraries; please use/nodefaultlib:library
1>e:\documents\visual Studio 2013\projects\consoleapplication5\debug\consoleapplication5.exe:fatal Error LNK1169: Find one or more multiple-defined symbols

Solution: Project Properties-Configuration Properties-C/C + +-code generation-Runtime, select/MT or/MD according to the compiled Libcurl version, set the project to release, platform x86

The recompile operation succeeded.


vc2008 build and use Libcurl static libraries: http://blog.csdn.net/mos2046/article/details/7697530


Related Article

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.