0

I just created an empty C++ project in VS2019. Installed Curl through NuGet together with openssl, ssh2 and zlib etc.

Now, what I would expect that it resolves the packages while building the solution, what else is a package manager for? Meh, I get the following errors:

Error   LNK2019 unresolved external symbol _curl_slist_append referenced in function "public: bool __thiscall checkApi(void)"

A well know error but I could find no solution for this issue. I tried adding it to additional libraries, I tried adding directories, folders, linkages nothing works. I have read the PDFS for VS2013 and 2015 they DONT work.

I hope anyone can point me in the right direction. It should not be this hard with a package manager or am I wrong?

I have (obviously)

#include "curl/curl.h"
#include "curl/easy.h"

And then a method doing:

this->chandle = curl_easy_init();
        if (this->chandle) {
            headers = curl_slist_append(headers, "Accept: application/json");
            headers = curl_slist_append(headers, "Content-Type: application/json");

            curl_easy_setopt(this->chandle, CURLOPT_VERBOSE, 1);
            curl_easy_setopt(this->chandle, CURLOPT_HTTPGET, 1);
            curl_easy_setopt(this->chandle, CURLOPT_URL, api_url);
            curl_easy_setopt(this->chandle, CURLOPT_HTTPHEADER, headers);

            CURLcode ccode = curl_easy_perform(this->chandle);
            curl_easy_cleanup(this->chandle);
        }

enter image description here

Digital Human
  • 1,599
  • 1
  • 16
  • 26
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Richard Critten Sep 24 '19 at 10:08
  • Is the error you show the *only* such linker error you get? – Some programmer dude Sep 24 '19 at 10:08
  • I get the error for every curl_ method that I call actually – Digital Human Sep 24 '19 at 10:10
  • Then it seems you don't link with the cURL library. – Some programmer dude Sep 24 '19 at 10:11
  • @RichardCritten no its not a duplicate. Far from even. Doesn't even looks the same or sounds the same. – Digital Human Sep 24 '19 at 10:11
  • @Someprogrammerdude I can't 'link' the library because then it tells me it cant find libcurl.lib or libcurl.dll. Doesn't matter which I try. That is whole fuckery here. – Digital Human Sep 24 '19 at 10:13
  • Did it build the needed packages? Did you add the libraries to the linker section of the main project? Did you turn on detailed linker output to check exactly what libraries are being linked? – Richard Critten Sep 24 '19 at 10:13
  • ***Where*** is the cURL library installed? Have you tried looking for its location? Have you added the location to the paths searched by the linker? – Some programmer dude Sep 24 '19 at 10:16
  • @RichardCritten yes I did. It doesn't even look for libcurl. Even when added to 'linker section' of the project. As far as my knowledge goes you only need to add libcurl.lib or curllib.dll and it should find it right? Never worked with NuGet in this way before. Do you need to add them with full path? Like C:\Users\\.nuget\ bla bla ? Sounds wrong.... – Digital Human Sep 24 '19 at 10:17
  • @Someprogrammerdude yes, NuGet installs them in C:\Users\\.nuget\packages\curl....... – Digital Human Sep 24 '19 at 10:18
  • It seems to me that the bigger question is "Why isn't my local NuGet installation and package directories added automatically to Visual Studio for C++ projects?" To which the answer is (from [the top of the NuGet front-page](https://www.nuget.org)) "NuGet is the package manager for **.NET**." (emphasis mine). It's not a package manager for plain C++ projects. – Some programmer dude Sep 24 '19 at 10:21
  • @Someprogrammerdude fair enough. – Digital Human Sep 24 '19 at 10:25
  • So, now its actually building. When executing the code it says: Missing libcurl.dll is missing from your computer :) – Digital Human Sep 24 '19 at 10:40

1 Answers1

0

So, I finally found some interesting information. Here is part of the solution:

How to use curl Nuget package in C++ application

In my case I added: Linker -> Input -> Additional Dependencies -> "libcurl.lib" Then VC++ Directories -> Include Directories -> "C:\Users\<username>\.nuget\packages\curl\7.30.0.2\build\native\lib\v110\Win32\Debug\dynamic;" And same value for Library Direcories.

Now I can build the solution, however still not able to run it. I follow up when that problem is solved to.

Digital Human
  • 1,599
  • 1
  • 16
  • 26