Use MinGW to statically cross-compile libcurl with zlib under Linux (including cross-compiling OpenSSL, i.e.--CROSS-COMPILE-PREFIX=I686-W64-MINGW32-MINGW)

Source: Internet
Author: User


Use MinGW to statically cross-compile libcurl with zlib under Linux


Libcurl is a cross-platform, easy-to-use, powerful network library. In most Linux distributions, a compiled binary package is available, and the Mac system is used as a core component. But on the Windows platform but need to manually compile, not to mention some people with special cleanliness (for example, I) also particularly hate to more than a few DLLs, do not want static link. This article, as a small summary of my two-night experience, explains how to use MinGW to compile the Libcurl static library used by Windows under Linux.


STEP1 Installing the MinGW compiler


This step I'm not going to say more, most of the Linux distribution repositories should have, take my archlinux for example, execute:


~# pacman -S mingw-w64


Can. If you don't need to cross-compile and compile directly on Windows, go to SourceForge to download the Windows version yourself. Don't worryw64if that is a 64-bit version, it compiles 32-bit and compiles 64-bit programs. Or in my version, for example:


~# pacman -Ql mingw-w64-gcc| grep ‘/usr/bin/.*gcc$‘
mingw-w64-gcc /usr/bin/i686-w64-mingw32-gcc
mingw-w64-gcc /usr/bin/x86_64-w64-mingw32-gcc


You can see that there are two gcc,i686-w64-mingw32-gcccompiled by the program is 32 bits, andx86_64-w64-mingw32-gcccompiled out is 64 bits. Now, write a Hello World (you can use my Hello World code ^_^), and then compile and try:


i686-w64-mingw32-gcc hello_world.c -o hello_world.exe


Take it to the virtual machine or throw it into wine, if it can run normally, then congratulations, the first step is completed.


STEP2 Download Source code


Very simple steps, if you do not make the suggestion directly to the upper right corner.


    • LibCurl: the topmost source Archives
    • ZLib: Please source Code
    • OpenSSL: Optional, do not compile if not necessary, will greatly increase the file volume


Putcurl-7.35.0andzlib-1.2.8(possibly alsoopenssl-1.0.1f) these folders in the same directory, and then proceed to the next step.


STEP3 compiling source code


Open thezlib/win32file under the folderMakefile.gcc,PREFIX =change this line to the GCC prefix in STEP1, for mePREFIX = i686-w64-mingw32-. Copy this file to azlibfolder, and then under thezlibfoldermake -f Makefile.gcc, you should be able to seelibz.athe file.



If you want to compile OpenSSL, then go to the OpenSSL folder


$ ./Configure no-shared --cross-compile-prefix=i686-w64-mingw32- mingw$ make


Can, remember to change prefix. Generatelibssl.aandlibcrypto.a



Finally go to Libcurl in the Lib folder to modify theMakefile.m32file,CC = $(CROSSPREFIX)gccadd a lineCROSSPREFIX=i686-w64-mingw32-(please modify), and then change the followingCFLAGSline to this, andCFLAGS = -g -O2 -Wall -DCURL_DISABLE_LDAPfinally


make -f Makefile.m32 CFG=-zlib


Or


make -f Makefile.m32 CFG=-zlib-ssl


Make to the end will report a mistake, because the document is not lil bit place, manually move it


1234 For x in vtls/openssl.o vtls/gtls.o vtls/vtls.o vtls/nss.o vtls/qssl.o VTLS/POLARSSL.O vtls/polarssl_ THREADLOCK.O vtls/axtls.o vtls/cyassl.o vtls/curl_schannel.o vtls/curl_darwinssl.o vtls/gskit.odo mv ' basename $x ' vtls Done


And then make a bit, thelibcurl.afile should appear.
It doesn't matter if you generate DLL errors, we want.afiles


STEP4 Test


Now, you can find a Libcurl demo to test. Note To add a macro definitionCURL_STATICLIB


i686-w64-mingw32-gcc -I. -L. -DCURL_STATICLIB curl_demo.c -lcurl -lz -lws2_32 -o curl_demo.exe


If you compile without knowing-I-Lthe use of GCC and options, please Google yourself. If you add SSL support, you need to link to more libraries, depending on the error message, Google. The last thing to remind: please put the -lcurloption behind the source file , I was because of this link but anyway. Finallycurl_demo.exedrag into the virtual machine, if everything is normal, then congratulations, you have succeeded.






http://recursiveg.me/2014/02/how-to-cross-compile-libcurl-on-linux/



Use MinGW to statically cross-compile libcurl with zlib under Linux (including cross-compiling OpenSSL, i.e.--CROSS-COMPILE-PREFIX=I686-W64-MINGW32-MINGW)


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.