23

I've been trying to use LibCURL in C++ for a couple hours now, and it is really getting on my nerves. I have a feeling someone else has had a problem like this before, but I haven't found and posts that have given me a solution.

This is what I've done:

Since the libCurl download page is so confusing, I am posting exactly what I've done. First, I downloaded the file at the top (curl-7.23.1.zip), and then opened it in winRAR. I then went into the include folder, and then extracted the 'curl' folder out of there.

enter image description here

I then created a new project with Code::Blocks, and then moved the 'curl' folder into the same folder as my project.

enter image description here

I then add '#include "curl/curl.h"' to the top of my file, and then try and initialize a simple CURL var... I then get an error, saying:

...\main.cpp|22|undefined reference to `_imp__curl_easy_init'|

Here is a picture of the actual code/error: enter image description here

Honestly, I think it is something very very stupid that I am doing, but I just don't know what to do.

Jaffa
  • 12,442
  • 4
  • 49
  • 101
hetelek
  • 3,776
  • 5
  • 35
  • 56

3 Answers3

14

Finally got it to work with some of help

Here is how I did it:

  1. Download the 'Win32 Generic' libcurl package. (7.24.0)
  2. In Code::Blocks, right click your project and open the build options.
  3. Go to 'Linker Settings' and add 'curldll' into the 'Link Libraries' listbox. (image)
  4. Go to 'Search Directories' and under 'Compiler' link it to the path of your 'curl-7.24.0-devel-mingw32\include' folder.
  5. Go to the 'Linker' tab under 'Search Directories', and add the path of your 'curl-7.24.0-devel-mingw32\lib' directory.
  6. Move all DLLs from your 'curl-7.24.0-devel-mingw32\bin' folder into your projects 'bin' folder.
  7. Build and enjoy

To use libCurl with Qt, it is a bit easier.

  1. Move all necessary files/dlls/libraries into your debug folder. Make sure that you include the 'curl' folder.

  2. Go to your .pro file, and add the location of the 'libcurldll.a' file. For example(mine):

    LIBS += C:\libcurl\7.24.0\lib\libcurldll.a

  3. Enjoy.

Thanks R. Martinho Fernandes!

Community
  • 1
  • 1
hetelek
  • 3,776
  • 5
  • 35
  • 56
2

You must also include the lib/ folder from libcurl, which contains *.a or *.dll files. Theses files are the library itself, the compiled binary on which you link your program.

If you link the library dynamically, you'll need to put the *.dll in your project directory, in C:\Windows or in C:\MinGW\bin (if C:\MinGW is the compiler path).

Jaffa
  • 12,442
  • 4
  • 49
  • 101
  • Could you possibly explain a bit further on what I would do? By the *.dll, are you referring to the 'libcurl.dll'? Thanks again. – hetelek Jan 16 '12 at 06:54
  • Yes, libcurl.dll and any other dll that you may found in your download. You need to extract the binary and put it in a place your OS will find it back. In order to statically link against the dll, it has to be placed in $COMPILER_PATH\lib, where $COMPILER_PATH is typically C:\MinGW with C::B – Jaffa Jan 16 '12 at 06:59
0

"First, I downloaded the file at the top (curl-7.23.1.zip), and then opened it in winRAR. I then went into the include folder, and then extracted the 'curl' folder out of there."

It sounds like you didn't compile the source code for curl. All the downloads at the top of the page are just source.

Wes Ovall
  • 9
  • 3
  • He didn't compile libcurl. I understand that his question is about compile errors in his project. They were caused because he's trying to include things that don't exist yet. (At least, that's what it looks like to me.) – Wes Ovall Jul 06 '16 at 06:25