简体   繁体   中英

C++ CURL Library Linker Error but included the right libs

So I am trying to integrate the curl library into my c++ project. I did the following steps:

  • download the curl library and extract it
  • running the developer console of visual studio 19 and running the following commands:
    • cd to the winbuild folder
    • set RTLIBCFG=static
    • nmake /f Makefile.vc mode=static vc=19 debug=yes
  • in builds folder I copied the bin, include and lib folder to my own visual studio project and set up the include directory under Settings > C/C++ > General > Additional Include Directories and the library directory under Settings > Linker > General > Additional Library Directories and then the actual lib files under Settings > Linker > Input > Additional Dependencies.

I thought this should be it to get CURL running, but I got a Linking error for every function call of the lib. EVEN after I added these libs to the additional dependencies setting in the linker input: Normaliz.lib;Ws2_32.lib;Wldap32.lib;Crypt32.lib;advapi32.lib;

Is there any solution available? In my searches on the internet I got always the solution, to include the Noraliz.lib;[...] and then it was told that it should run but it did not work for me. Would be happy about some help. Here is the code I tried to compile:

#include <iostream>
#define CURL_STATICLIB
#include <curl/curl.h>
#include <iostream>

static int writer(char* data, size_t size, size_t nmemb, std::string* writerData)
    {
    if (writerData == NULL)
        return 0;

    writerData->append(data, size * nmemb);
    return size * nmemb;
    }

int main(int argc, char** argv)
    {
    std::string content;

    curl_global_init(CURL_GLOBAL_ALL);
    CURL* curl = curl_easy_init();

    if (curl)
        {
        curl_easy_setopt(curl, CURLOPT_URL, "");
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &content);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
        CURLcode code = curl_easy_perform(curl);
        }

    curl_easy_cleanup(curl);
    curl_global_cleanup();

    return 0;
    }

you need add CURL_STATICLIB macro defined in the "Preprocessor Definitions" section.


Maybe you can try teemo library, it based libcurl.

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