Libcurl.lib Static Library under Windows compilation

Source: Internet
Author: User

1. Download the latest version of Libcurl, my is Curl-7.44.0.zip, unzip, enter the directory winbuild, carefully 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 following include and Lib two folders

Document inside a paragraph like this

Static linking of Microsoft ' s C RunTime (CRT):
==============================================
If you are using mode=static nmake would 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 use that
option, and NMAKE would default to the DLL CRT. Rtlibcfg is rarely used and
Therefore rarely tested. When passing rtlibcfg-a configuration that is
Already built but not with ' option, or if the option was specified
Differently, you 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-Runtime)/MT and/MD (/MTD and/MDD are corresponding debug versions)

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


2. Open VS2013 New Project Select Win32 Console Application, additional options select Empty Project

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

Create a new CPP file and test to see 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 the function entry

Solution: Open Project Properties, configure properties-c/C + +-preprocessor-preprocessor definition-open drop-down box-edit-text box input Curl_staticlib-Save

Re-compiling

Error:

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

Solution: Project Properties-Configuration Properties-C/C + +-code generation-Runtime, select/MT or/MD based on the compiled Libcurl version

The recompile runs successfully.


vc2008 building and using Libcurl Static library: http://blog.csdn.net/mos2046/article/details/7697530


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Libcurl.lib Static Library under Windows compilation

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.