1

I've been getting this error for a while now, so as a last resort I followed This video to the letter.. and still got the same errors. So, here's the code I produced:

#include <iostream>
#include <string>

#define CURL_STATIC
#include "curl/curl.h"

#ifdef _DEBUG
#   pragma comment (lib, "curl/libcurl_a_debug.lib")
#else
#   pragma comment (lib, "curl/libcurl_debug.lib")
#endif

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 wmain(int argc, wchar_t *argv[], wchar_t *envp[])
{
    std::cout << "Hello curl!";

    std::string content;

    curl_global_init(CURL_GLOBAL_ALL);

    CURL *curl = nullptr;

    curl = curl_easy_init();

    if (curl)
    {
        curl_easy_setopt(curl, CURLOPT_URL, "https://www.youtube.com/watch?v=wjNyT5PhNvI&t=417s");
        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();

    std::cout << content;

    std::cin.get();
}

And the errors:

1>------ Build started: Project: curl_test, Configuration: Debug Win32 ------
1>main.cpp
1>main.obj : error LNK2019: unresolved external symbol __imp__curl_global_init referenced in function _wmain
1>main.obj : error LNK2019: unresolved external symbol __imp__curl_global_cleanup referenced in function _wmain
1>main.obj : error LNK2019: unresolved external symbol __imp__curl_easy_init referenced in function _wmain
1>main.obj : error LNK2019: unresolved external symbol __imp__curl_easy_setopt referenced in function _wmain
1>main.obj : error LNK2019: unresolved external symbol __imp__curl_easy_perform referenced in function _wmain
1>main.obj : error LNK2019: unresolved external symbol __imp__curl_easy_cleanup referenced in function _wmain
1>c:\users\james\source\repos\curl_test\Debug\curl_test.exe : fatal error LNK1120: 6 unresolved externals
1>Done building project "curl_test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Does anyone know what could be causing this? The Linker susbsytem is set to console, the character set is set to unicode, and MFC is set to be used in a static library.

Yawning Gull
  • 11
  • 1
  • 3
  • do you have `libcurl_a_debug.lib` linked in your library? – macroland Jun 04 '18 at 00:56
  • 1
    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) – Ken White Jun 04 '18 at 00:57
  • @KenWhite, too broad to help him. – Arash Jun 04 '18 at 01:16
  • @Arash: No, it's not. We cannot possibly have every individual possible unresolved reference in an individual question. That is the canonical duplicate for this question. – Ken White Jun 04 '18 at 01:18
  • 2
    See this curl FAQ entry on the `__imp` symbol errors: https://curl.haxx.se/docs/faq.html#Link_errors_when_building_libcur – Daniel Stenberg Jun 04 '18 at 07:35
  • It looks stupid but could you please replace `# pragma` by `#pragma` without spaces between `#` and `pragma`? – Arash Jun 05 '18 at 05:31
  • Please refer to the below page. https://stackoverflow.com/questions/28266953/error-lnk2019-unresolved-external-symbol-libcurl-visual-studio – Dattatraya Mengudale Sep 28 '22 at 13:56

0 Answers0