0

I am having some big headaches linking statically libcurl in MSYS2 mingw. I installed libcurl and all the listed dependencies from here

https://packages.msys2.org/package/mingw-w64-x86_64-curl

Since I am using CodeBlocks as IDE I need to supply a whole list of libs in form of lib#?.a, please keep in mind that I know nothing of Linux world and gcc tools and command line, otherwise I wouldn't be using an IDE!

Also I am not skilled enough to compile lib packages. I just need to write some portable code to do a https post request in cpp, so I need libcurl.

Can you tell me a complete list of all the needed libs to link against ? I tried all my best but I keep getting an infinity of unresolved symbols

UPDATE

After having checked what the package config for libcurl says, I have installed all the missing libs and used the following command line:

g++.exe -o MyProg.exe obj\Release\main.o -static-libstdc++ -static-libgcc -static -m64 -lcurl -lnghttp2 -lidn2 -lssh2 -lpsl -ladvapi32 -lcrypt32 -lssl -lcrypto -lssl -lcrypto -lgdi32 -lwldap32 -lzstd -lbrotlidec -lz -lws2_32 -s

Despite that I am still getting tons of undefined references:

d:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: d:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib\libcurl.a(gsasl.o):(.text+0x14): undefined reference to `gsasl_init'

[plus many other 'gsasl...' referrences]

d:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: d:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../lib\libbrotlidec.a(decode.c.o):(.text+0x2d28): undefined reference to `BrotliTransformDictionaryWord'

[plus many other 'brotli...' references]

3
  • I suggest you use cpp-httplib. It's portable and header only library, no custom linker steps are required. Unless you want to enable https support.
    – 3CxEZiVlQ
    Commented May 19, 2022 at 0:28
  • @273K sadly I am forced to have HTTPS support :(
    – elena
    Commented May 19, 2022 at 19:19
  • If you focused on HTTPS, then you will apply the same options after libcurl.
    – 3CxEZiVlQ
    Commented May 19, 2022 at 20:34

1 Answer 1

1

pkg-config will tell you the necessary flags. Install it from the package mingw-w64-x86_64-pkg-config.

Run it as pkg-config --libs --static libcurl.

Copy the output into "linker flags -> other". For me the output is -L/mingw64/lib -lcurl -lnghttp2 -lidn2 -lssh2 -lpsl -ladvapi32 -lcrypt32 -lssl -lcrypto -lssl -lcrypto -lgdi32 -lwldap32 -lzstd -lbrotlidec -lz -lws2_32. Don't forget to add the --static flag, if you're not already doing so.

10
  • Thanks HolyBlackCat... that was actually what I already did by looking at what the package config says. Unfortunately it does not work, I keep getting undefined references. I really don't know what I am still doing wrong. This is my command line: g++.exe -o Workbench.exe obj\Release\main.o -static-libstdc++ -static-libgcc -static -m64 -lcurl -lnghttp2 -lidn2 -lssh2 -lpsl -ladvapi32 -lcrypt32 -lssl -lcrypto -lssl -lcrypto -lgdi32 -lwldap32 -lzstd -lbrotlidec -lz -lws2_32 -s. I am not allowed to post the full output because it is too long sadly
    – elena
    Commented May 19, 2022 at 19:09
  • @elena The output you posted hints that you have some other MinGW version installed, which somehow interferes. Remove it. Also, I believe -m64 is unnecessary (MINGW64 compiler defaults to 64 bits), and so are -static-libstdc++ -static-libgcc (they're implied by -static). Commented May 19, 2022 at 19:20
  • #HolyBlackCat thanks for your patience. Those flags are set by Code::Blocks, however I removed them and I just left -static, no hope. Re: some other MinGW version, that is unlike since I am using a freshly installed MSYS2 and my IDE points to its mingw64 dir only and nothing else...
    – elena
    Commented May 19, 2022 at 19:25
  • @elena Then what's in d:/mingw64_prev? Commented May 19, 2022 at 20:01
  • 1
    @elena I could swear it worked for me yesterday, but apparently I tested it incorrectly; I do reproduce the problem. Apparently it's already been reported. Though I would remove d:/mingw64_prev, since it shouldn't appear in the output at all. At least remove it from the PATH. Commented May 20, 2022 at 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.