Libcurl supports OpenSSL cross-compiling MIPS rt5350

Source: Internet
Author: User
Tags function prototype openssl library vcard

ByAdmin | November 18 0 commentadvertisement

After half a month to finally compile the Libcurl library, referring to many blogs on the internet, and eventually compiled their own library.

First of all, I want the purpose of this library. I'm running on the RT5350. OpenWrt need to submit data to the server, using the HTTP protocol, and require SSL encryption. After online search only libcurl appropriate, so I began to cross-compile libcurl with MIPSEL-OPENWRT-LINUX-GCC,

The beginning of the time has been in the CSDN download Libcurl source code package, the version is not the same makefile there will be differences, has been error, specific errors I did not record a pity, later I found a relatively new version of GitHub curl-7.51.0.tar.gz It is best to go to the official website to download I may just start the source package is wrong. After a week of tossing finally put this compile, but I want to support HTTPS so also need to add OpenSSL, reference blog,
But the blog that other people write is not necessarily suitable for their own use, so I recorded this blog

First, compile Libcurl with MIPSEL-OPENWRT-LINUX-GCC

If you do not need to support SSL, configure the time to turn off SSL

1. Unzip the installation package TAR-XVF curl-7.51.0.tar.gz

2. Go to the Catalog CD curl-7.51.0

3. Configuration./configure--prefix=/opt/libcurl-lib CC=MIPSEL-OPENWRT-LINUX-GCC--host=mipsel-linux-with-ssl=/opt/ openssl-lib/

--prefix behind is you when the library to put the place, just like the Linux software installed where, because I do not want to run in the virtual machine as long as this library, so choose/opt/libcurl-lib This directory, then the next step to know

Cc= This is the configuration cross-compilation chain

--host=mipsel-linux This online said is the target machine, that is, the library will compile the program to run the device, I do not understand

-with-ssl=/opt/openssl-lib/This is to open SSL, some version of the default is to open some of the default off, you go to see it haha, =/opt/openssl-lib/This is your reliance on the library where I put it, and later will tell why

4. Compile make-j4-j4 to compile faster as if it were 4 cores.

5. Install (build library) make install this step will put the generated library and so on in the configuration of the time this inside--prefix=/opt/libcurl-lib should be the source package that the need to copy into this area

Second, the above said the need to rely on the library OpenSSL library, let's compile OpenSSL together.

SOURCE Package openssl-1.0.1u.tar.gz

First of all, why did not choose to compare the new version, because I used a lot of versions, makefile are different for reference blog http://blog.csdn.net/clirus/article/details/50151427

I chose the version that was closer to him, but he said, "If it is MIPS cross-compiling, you still need to remove the-m64 suffix from this makefile file after modifying makefile." "I don't have this step, I can't find-m64.

1. Unzip

2. Enter the catalogue

3. Configuration./config No-asm shared--prefix=/opt/openssl-lib--cross-compile-prefix=mipsel-openwrt-linux-

No-asm This I also do not know what to say do not rely on the assembly what, do not understand and then add up

Shared this is because you need to generate a dynamic library, if you do not add a shared compile time will not have-fpic, to observe, but in the compilation of Libcurl when the error said what compile time without-fpic, I press the online said in makefile Modify Plus-fpic is useless, so just add gkfx.

--prefix=/opt/openssl-lib This is mentioned above is the generated library to put in here, compile Libcurl when the dependency library path will be assigned to this

--cross-compile-prefix=mipsel-openwrt-linux-This is the configuration cross-compilation chain

The above one or two order is reversed in fact is to compile OpenSSL, and then compile Libcurl

Finally compiled, eh .....

Test the program, too.

#include <string>using namespace std; FILE *fp;//This function is constructed to conform to curlopt_writefunction//complete data saving function size_t writedata (void *ptr, size_t size, size_t nmemb, void *    Stream) {int written = Fwrite (ptr, size, NMEMB, (FILE *) FP); return written;}    int PostURL (char *struserpassword) {CURL *curl;    Curlcode Res;    struct Curl_httppost *post=null;    struct Curl_httppost *last=null; String strcredstr =//String Strcurlopt_url =//The server address itself to be connected if ((Fp=fopen ("/opt/1.txt", "W") ==null) {printf ("FOP    En (/opt/1.txt) fail\n "); exit (1);}    Curl = Curl_easy_init (); if (Curl) {curl_easy_setopt (curl, CURLOPT_URL,STRCURLOPT_URL.C_STR ());//Specify the URL curl_formadd (&post,        &last, Curlform_copyname, "Grant_type", Curlform_copycontents, Strcredstr.c_str (), curlform_end);        Curl_easy_setopt (Curl, curlopt_httppost, post);        Curl_easy_setopt (Curl, Curlopt_ssl_verifypeer, 0L);        Curl_easy_setopt (Curl, Curlopt_ssl_verifyhost, 0L); Curl_easy_setopt (Curl, Curlopt_userpwd, Struserpassword); Curlopt_writefunction the subsequent action to the WRITE_DATA function processing//callback function prototype: size_t functions (void *ptr, size_t size, size_t nmemb, Voi        D *stream);        The function will be called after the Libcurl receives the data, so the function does more data saving functions, such as processing the download file. Curlopt_writedata is used to indicate the source of the stream pointer in the Curlopt_writefunction function.        Curl_easy_setopt (Curl, curlopt_writefunction, writedata); res = curl_easy_perform (curl);        printf ("%d%s\n", Res, Curl_easy_strerror (res));    Curl_easy_cleanup (curl);    } fclose (FP); return 1;} int main (void) {string strusername = "401f8c403a9447119d722b592b2c9957"; string strpassword = " 415d320b18974921b66569d6a89ef369 "; char acusername[1024] =" "; snprintf (Acusername, sizeof (Acusername),"%s:%s ", Strusername.c_str (), Strpassword.c_str ()), Curl_global_init (CURL_GLOBAL_SSL);p Osturl (acusername);}

Oh, yes. There is also a point is to add the library, in the Eclipse Gakou still have order, to try it yourself I can not speak clearly, I do not know why. If you don't know, leave a message.

Http://www.yaoguangkeji.com/a_7kGzGWn3.html

Libcurl supports OpenSSL cross-compiling MIPS rt5350

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.