How do I include curl library in my C project in Code Blocks (Windows)?

后端 未结 2 1863
傲寒
傲寒 2020-12-20 07:29

The question seems straight forward. I tried a lot of things just to include curl in my C project using the code::blocks ide but to no avail.

I would like to use cUR

相关标签:
2条回答
  • 2020-12-20 07:43

    Go to your project "Build Options" -> "Linker" tab and so you have two choices:

    1. If your library is (correctly) installed system-wide, write in "other linker options" the libs as if you were using your compiler directly. For GCC you'd write -lcurl. You may also use this with a path instruction like Wl,-rpath,/path/to/your/library -lMyLib. Obviously it depends on the compiler and system setup.

    2. Add the library in "Link libraries" on the left. Click the "Add" button and browse to your library file.

    Take a look at this A.3 — Using libraries with Code::Blocks for some pictures. Googling around will show you more.

    0 讨论(0)
  • 2020-12-20 07:45

    The following steps are for windows 32 users. And the following steps worked for me after several hours. This may or may not work for you as I got it after several trial and errors. So thats why I am writing the steps in elaborate manner.

    step1: start code blocks create an empty project with name proj_curl

    step2: Open on this url www.paehl.com/open_source/?CURL_7.50.0

    • in this site download

    a) click Download without ssl

    b) click Download libcurl.dll (all versions) only

    c) click Download the Libray (all version) only

    step3: open on this url curl.haxx.se/download/curl-7.50.1.zip - a zip file will be downloaded automatically. (sorry folks this site is not allowing me to insert more than 2 links, bear with me.)

    Note: Now Totally You have 4 zip files downloaded

    1. curl_750_0.zip (which contains curl.exe file)
    2. curl_DLL_ONLY.7z(which contains folders such as nossl, RTMP, ssh...etc.)
    3. Curl_lib.7z(which contains lib folder)
    4. curl-7.50.1.zip(which contains curl-7.50.1 folder)

    step4: create a folder in c drive(c:\libs\curl) extract all the folders files of the 4 zip files into the curl folder in c. Make sure to create each subdirectory for each zip file.

    step5:(Very important)

    In the curl folder of C drive, - click on curl.exe(a command prompt just appears for few millisecs.) - Go to code blocks -> Settings -> Compiler... -> Linker settings tab -> Add

    "C:\libs\curl\lib\nossl\libcurl.a"

    "C:\libs\curl\lib\nossl\libcurldll.a"

    then -> search directories tab -> Compiler enter image description here

    then -> search directories tab -> Linker enter image description here

    Click ok

    Step6: - open the folder "nossl" which came in the curl_DLL_ONLY.7z file.

    • copy the libcurl.dll file to the bin\debug folder of the code blocks project.

    Step7: Now test the working of the curl library with your c program.

    Note: if you encounter an error "The program cant start because zlib1.dll is missing from your computer. Try reinstalling the program to fix this problem."

    Solution: - copy and paste the url sourceforge.net/projects/mingw/files/latest/download

    • install the mingw-get-setup.exe by marking all the libraries.(takes about 10 min to install)

    • after installation, open C:\MinGW\bin, copy the zlib1.dll to the same directory as you did in step6 for libcurl.dll.

    Thats it...

    0 讨论(0)
提交回复
热议问题