简体   繁体   中英

C++ Codeblocks + libcurl ends up with link errors

Hi I am a C++ beginner and I wanted to learn about http requests... I picked cURL because I have experience using it before with php. I downloaded this version from cURL website into C:\\libs
Win64 x86_64 7zip 7.51.0 binary SSL SSH Viktor Szakáts 1.81 MB

This is what I've done so far on Codeblocks:

  1. Under Global compiler settings/Search directories/Compiler, I added this path: C:\\libs\\curl-7.51.0-win64-mingw\\include\\curl

  2. Under Global compiler settings/Search directories/Linker, I added this path: C:\\libs\\curl-7.51.0-win64-mingw\\lib

  3. Under Global compiler settings/Linker settings, I added this paths: C:\\libs\\curl-7.51.0-win64-mingw\\lib\\libcurl.a C:\\libs\\curl-7.51.0-win64-mingw\\lib\\libcurldll.a

-Under Global compiler settings/compiler settings, this box is checked from before: Have g++ follow the C++11 standard... (no idea if this matters or not...)

Also, because I was desperate I copied the contents of C:\\libs\\curl-7.51.0-win64-mingw to C:\\Program Files (x86)\\CodeBlocks\\MinGW, this step makes no sense to me, but I found it online so I tried...

Now I am running this code:

#include <cstring>
#include <string>
#include <iostream>
#include <stdio.h>
#include <curl.h>
#include <easy.h>
using namespace std;

int main(){

CURL* curl = curl_easy_init();
if(!curl){
        cout << "error" << endl;
    }else{
     cout << "good job!" << endl;
     curl_easy_cleanup(curl);
    }
};

I am getting this errors:

undefined reference to `_imp__curl_easy_init'
undefined reference to `_imp__curl_easy_cleanup'
error: ld returned 1 exit status
Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) 

For some reason, including include curl/curl.h does not work, only way it works is including curl.h, same for easy.h

Any advice appreciated! Thanks in advance!

You're linking with a static libcurl (on Windows) without having -DCURL_STATICLIB added to your CFLAGS when you build your application.

That is, you must define CURL_STATICLIB before the curl headers are included.

Described in the curl FAQ item Link errors when building libcurl on Windows

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM