Skip to main content

[curl]First curl program with Code::Block

Code::Block is tiny powerful cross-platform IDE for C/C++ program. However, the pre-installed complier is 32-bit.
Both curl and openSSL is needed in this tutorial. Hence, it is really important to make sure if they are also installed accordingly.

Compiler of your Code::Block can be check from:
Setting>Toolchan executables
enter image description here
It shows that the compiler is located at C:\MinGW and it is Win32 based.

Both Curl and openSSL need to be download for this tutorial.It is
highly recommended to install all the program with win32 version!!

1. Download and install the openSSL

openSSL can be download from this location.
https://slproweb.com/products/Win32OpenSSL.html
enter image description here

In this demo, full version of v1.1 is installed. The openSSL folder will be located at C:\OpenSSL-Win32
enter image description here

2. Download and install curl

You can find the guideline to setup curl properly from previous article. Just need to remind again that Win32 version is needed in this case.
https://aconcaguacode.blogspot.tw/2017/07/curl-how-to-install-curl-on-windows.html#more

3. Start a new project on Code::Block

Click on File>New>Project and start a new project.
enter image description here

Choose the Console application and choose C as the language.
enter image description here
enter image description here

Type in the Project name and Folder to create project
enter image description here
Here, I choose the folder of this project to be in:

C:\codeBlockProject\firstCurl

Click next to choose the preset GCC complier.

4. Setup the the Library

Here comes the most important part. In order to let the C/C++ program find the proper .h file and library file. Some parameter need to be setup in the Project’s Build option. Right click on project and choose:
Build Options>Linker settings
Set the location of libcurl.a and libcurldll.a to the Link libraries. and click OK.

enter image description here

In my case, location of libcurl.a and libcurldll.a is within the folder of:

C:\curl-7.54.1-win32-mingw\curl-7.54.1-win32-mingw\lib\

5. Setup the the Linker(header)

Click Search directories>Add.
Linker is the directories of header file, which is located at :

C:\curl-7.54.1-win32-mingw\curl-7.54.1-win32-mingw\include\

enter image description here

Click on OK after the directory of curl header file has been setteed.

6. Test run with Simple.c

The Simple.c testing code can be download from:
https://curl.haxx.se/libcurl/c/simple.html
It can be used to estimate wheather the environment of curl is setup properly.After you paste in the testing code, click on hotkey [F9] on your keyboard or Build>Build and Run.
enter image description here

Simple.c is a basic code to access http://example.com with C code. It means that you have setup the environment properly if you can see the HTLM of example.com being download in your command line.
enter image description here

Well done!

Comments

Popular posts from this blog

[MinGW] Fix [Linker error] undefined reference to '_imp__curl_easy_init'

Recently, I found some error during the compiling progress of my curl program with Code::Blocks. The error keep showing in Code::Blocks like this: [Linker error] undefined reference to `_imp__curl_easy_init' I try to repair the Linker settings and Search directories but found out that there’s nothing wrong with it. It turns out the MinGW version has been modified to Win64 version last time when I was trying to deal with some W64 programs few days ago. I found that the MinGW download directly from the official website cannot be used in Code::Block properly. Hence, I use tdm-gcc instead . Here’s the procedure to fix the curl reference error. Download the tdm32 bundle from: http://tdm-gcc.tdragon.net/ Install MinGW/TDM(32-bit) by just clicking Next in the next few steps After the installation process, the MinGW will be installed under C:\TDM-GCC-32 Open your Code::Blocks program and go to Settings>Compiler Change the setting as followed Now th...

[curl] how to install curl on windows

How to install Curl on windows Curl is a universal library and command-line tool for data transferring with various common protocols. The protocols including DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, Telnet and TFTP. Curl also supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, HTTP/2, cookies, user+password authentication (Basic, Plain, Digest, CRAM-MD5, NTLM, Negotiate and Kerberos), file transfer resume, proxy tunneling and more. However, Curl is not preinstalled in the windows system. But it can be easily build up in your windows system followed by these few steps. 1. Download curl from internet Connect to https://curl.haxx.se and click on download . 2. Download the curl package Please choose the package that suit for your system. In this demonstration, I used the version 7.54.1 provided by Viktor Szakáts . 3. Unzip the file an...