5

Yes, I am aware that this is a linker error to the libcurl.lib I assume? I've tried downloading libcurl from a different source and put it in different places.

These are the errors:

LibFuckingCurl.obj : error LNK2019: unresolved external symbol __imp__curl_easy_strerror referenced in function _main

and 4 more of the same kind.

This is the sample code

#include <stdio.h>
#include <curl.h>

int main(void)
{
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
        /* example.com is redirected, so we tell libcurl to follow redirection */
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

        /* Perform the request, res will get the return code */
        res = curl_easy_perform(curl);
        /* Check for errors */
        if (res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
            curl_easy_strerror(res));

        /* always cleanup */
        curl_easy_cleanup(curl);
    }
    return 0;
}

Properties for project C/C++ General -> Additional Include Directories -> C:/Project/libcurl/include

Linker General ->Additional Library Directories -> C:/Project/libcurl/lib

Input -> Additional Dependencies -> libcurl.lib

Commandline: Here I can read that libcurl.lib is stated

Assuming this structure:
Project
    lib
        libcurl.dll
        libcurl.lib
       ... dll's
    include
       curl.h
       curlbuild.h
            ... all the header files
    VisualStudio (where VS puts the project)

I also tried putting the includes in the VC++ option for directory and library path. I've read numerous guides, posts, people who had the same problem and forgot to include the libcurl.lib

I downloaded one of the prebuilt versions of libcurl because CMake almost killed me yesterday.

Flexo
  • 87,323
  • 22
  • 191
  • 272
buddhabath
  • 664
  • 1
  • 10
  • 22
  • Also, these are one of the tutorials i tried. http://curl.haxx.se/libcurl/c/visual_studio.pdf I also try downloading the source and making it. – buddhabath Feb 02 '15 at 11:36

1 Answers1

11

Working on Visual Studio 2013 using Static Library

I got it to work now, thanks to some angel. Found this git repo: https://github.com/blackrosezy/build-libcurl-windows

Ran the .bat which also generated static libraries like the downloads before didnt.

How to:

Run the .bat included in the repository.

libcurl will be found in the thirdparty subfolder containing folders include and lib.

Create a new Visual Studio Project

Properties -> VC++ -> Add Directory thirdparty/include (the path)

Properties -> VC++ -> Add Library thirdparty/lib/static-debug (the path)

Properties -> C++ -> Preprocessor -> Add CURL_STATICLIB

Linker -> General -> Additional Library Directories Library -> thirdparty/lib/static-debug (the path) Linker -> Input add: C:\xxx\xxx\xxx\build-libcurl-windows\third-party\libcurl\lib\static-debug\libcurl_a_debug.lib (the full path of the lib file)

buddhabath
  • 664
  • 1
  • 10
  • 22
  • 1
    I had the same problem as you! A full day yesterday and 5 hours today trying various ways to build libcurl as a static library with SSL support. Never succeeded with openSSL but I did get something for WinSSL. Then I copied the library into my other libs and it STILL gave an unresolved symbol, extern "C" and all. Thank god you mentioned the preprocessor "CURL_STATICLIB". That solved the problem. Not ONCE in all my googlings and reading of instructions did I see that. I would have never guessed that would have been the problem. – Brian Reinhold Oct 10 '16 at 14:38
  • awesome, thank you. Any reason, why CURL_STATICLIB has to be added? Never seen a library that needs such a step to link the static lib successfully... – Micka Mar 02 '18 at 08:53
  • 1
    @Micka See this: https://github.com/curl/curl/issues/2196 ...And the last sentence: "This is by design..." – Emil Mocan Nov 20 '19 at 11:50