0

I'm trying to build a C++ application with the curl.h library, I'm using the following implementation:

#include <curl/curl.h>
int main(void)
{
    CURL *curl;
    CURLcode res;
    curl_global_init(CURL_GLOBAL_ALL);

    curl = curl_easy_init();
    if (curl)
    {
        curl_easy_setopt(curl, CURLOPT_URL, "....");
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "...");

        res = curl_easy_perform(curl);

        if (res != CURLE_OK)
           fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));

        curl_easy_cleanup(curl);
   }
   curl_global_cleanup();
   return 0;
 }

I've already copied the curl-7.85.0_1-win64-mingw library files into the Mingw folder, but when I compile I'm getting the following message:

C:\Users\Teste\AppData\Local\Temp\ccQE8stl.o:SendMsgClient.cpp:(.text+0x16): undefined reference to _imp__curl_global_init' C:\Users\Teste\AppData\Local\Temp\ccQE8stl.o:SendMsgClient.cpp:(.text+0x1d): undefined reference to _imp__curl_easy_init' C:\Users\Teste\AppData\Local\Temp\ccQE8stl.o:SendMsgClient.cpp:(.text+0x4a): undefined reference to _imp__curl_easy_setopt' C:\Users\Teste\AppData\Local\Temp\ccQE8stl.o:SendMsgClient.cpp:(.text+0x68): undefined reference to _imp__curl_easy_setopt' C:\Users\Teste\AppData\Local\Temp\ccQE8stl.o:SendMsgClient.cpp:(.text+0x76): undefined reference to _imp__curl_easy_perform' C:\Users\Teste\AppData\Local\Temp\ccQE8stl.o:SendMsgClient.cpp:(.text+0x8f): undefined reference to _imp__curl_easy_strerror' C:\Users\Teste\AppData\Local\Temp\ccQE8stl.o:SendMsgClient.cpp:(.text+0xb9): undefined reference to _imp__curl_easy_cleanup' C:\Users\Teste\AppData\Local\Temp\ccQE8stl.o:SendMsgClient.cpp:(.text+0xc0): undefined reference to _imp__curl_global_cleanup'

These were the commands I used to try to compile:

g++ ./SendMsgClient.cpp -lcurl

g++ -L..\lib\curl\lib64 -I..\lib\curl\include -lcurl ./SendMsgClient.cpp

mingw32-g++ ./SendMsgClient.cpp -lcurl

I can compile on Linux with:

g++ ./SendMsgClient.cpp -lcurl

PS: I don't use any kind of IDE.

Aamir
  • 1,974
  • 1
  • 14
  • 18
  • On a first glance it looks like you are trying to link with static lib curl while your caller is expecting the dll import lib. Check that you are using proper preprocessor definitions in your project - so that you have match. – Artemy Vysotsky Sep 17 '22 at 13:20
  • In fact, what I did was create a .cpp file in a simple text editor and then build it, I did the same process I did on Linux and it worked, so on Windows is there anything else to configure? – Maykon Luiz Matos Araujo Sep 17 '22 at 13:29
  • My advice is to install msys2 and use it's package management (pacman) to install MinGW and all of your dependent libraries like curl: [https://packages.msys2.org/base/mingw-w64-curl](https://packages.msys2.org/base/mingw-w64-curl) With msys2 it's very easy to install many opensource libraries. Most involve a single line pasted into your mingw64 terminal and the help page for each package shows the exact line to paste and has a convenient button that copies the text from the web page to your clipboard. – drescherjm Sep 17 '22 at 14:02
  • 1
    The command to install 64 bit curl for MinGW is: `pacman -S mingw-w64-x86_64-curl` shown on this page: [https://packages.msys2.org/package/mingw-w64-x86_64-curl?repo=mingw64](https://packages.msys2.org/package/mingw-w64-x86_64-curl?repo=mingw64) – drescherjm Sep 17 '22 at 14:06
  • Says package doesn't exist Target not found: mingw-w64-x86_64-curl – Maykon Luiz Matos Araujo Sep 17 '22 at 14:40
  • Works for me without issue. Not sure what is wrong with your msys2 installation. Maybe try `pacman -Syuu` first. – drescherjm Sep 17 '22 at 15:41
  • Now appears: error: mingw32 the key xxxxxxxxx unknown key – Maykon Luiz Matos Araujo Sep 17 '22 at 16:30
  • I found another way, on Linux, I copied the file libcurl.dll.a to /usr/x86_64-w64-mingw32/lib and with the command x86_64-w64-mingw32-g++ SendMsgClient.cpp -lcurl I get the build, but when I try to run on windows it asks for a bunch of dlls. – Maykon Luiz Matos Araujo Sep 17 '22 at 16:59
  • Does this answer your question? [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 Sep 18 '22 at 22:42
  • 1
    You should double comfirm the curl static lib can be found by your linker. – Frank Sep 19 '22 at 01:18

0 Answers0