Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error LNK2019: unresolved external symbol libcurl Visual studio

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.

like image 956
buddhabath Avatar asked Dec 20 '22 07:12

buddhabath


1 Answers

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)

like image 167
buddhabath Avatar answered Jan 13 '23 13:01

buddhabath