Reputation: 317
I am asking here because I couldn't get any support elsewhere. Also consider that I am quite a beginner so bear patience.
I am using Winlibs (winlibs.com, a ready to use mingw gcc10+ distribution) to code under Windows because after having tried other alternatives I judged it the best to my purposes, easiest to install and the most functional. I never had any problems with it.
But recently I had the need of writing some simple code to send a POST request. I wanted to do it in a possibly portable and c++ friendly manner, so I was suggested to use Curl. No libcurl is included in winlibs so I tried to load one from here
I chose the windows 64 binary of course (7.83.1) since I am working on windows 64 with winlibs 64. I installed everything in the right place and linked against libcurl.a.
Unfortunately the linker complains of unresolved symbols so I have to supppose the curl binaries I used are not suitable.
How can I use libcurl with winlibs then ? Before bothering here I really googled but could find no info!
Upvotes: 1
Views: 1352
Reputation: 7305
The MinGW-w64 tools from https://winlibs.com/ are only a build toolchain, so they don't contain libraries for you to link with (yet).
You need a Windows build of libcurl and use that.
To use it you must include the location to the header files using the -I
compiler flag, and then link with the library by pointing to the location of the .a
file with the -L
linker flag and then link with the library using the -l
flag (-lcurl
in this case). If you don't have .a
files you can also try to link with the full path of the .dll
file and gcc will know it's a shared library.
An easier way is to get libcurl via MSYS2's pacman
package manager.
If you want to statically link you need to use the output of pkg-config --static --libs libcurl
as link flags.
In practice though I noticed that sometomes pkg-config --static --libs libcurl
is missing some dependencies and you still need to add some manually. An example of a project of mine that builds on Windows with winlibs MinGW-w64 (both 32-bit and 64-bit) can be found at https://github.com/brechtsanders/winlibs_tools/blob/main/Makefile (specifically look for the definition of CURL_LDFLAGS
)
Upvotes: 1