Good afternoon, ladies and gentlemen. I'm trying to connect libcurl.a to the project in Code :: Blocks MinGW. I dropped the headers in the include and .a file in the lib, I set the link, #define and the -static parameter, but nothing happens, as there was an error saying curl_easy_init() not found, so it is.

So, is there anywhere a detailed instruction for connecting exactly static libraries to the C project.

1 answer 1

The feature of connecting static libraries is that, in addition to connecting the library itself, you can connect all its dependencies, which, in turn, can include both static libraries and dll.

As for libcurl , depending on the options with which it was compiled, this library may depend on a whole heap of third-party libraries (besides the system libraries).

As I have recommended here , the collected libcurl and its dependencies can be found here in this repository: https://bintray.com/vszakats/generic

For static linking of this version of curl , 3 more libraries from that repository will be needed: libssh2 , nghttp2 , openssl . Also, for the assembly will need zlib . To build all the libraries, MinGW-w64 version 6.2.0 is used , which also includes zlib , so I recommend to take the same version.

To make a project in Code :: Blocks portable, the specified libraries and their headers are best copied, not to the MinGW directory, but somewhere within the project folder (for example, to the lib and include folders).

Next, you need to open the project settings Project - Build options and register:

  • on the Compiler settings - #defines tab Compiler settings - #defines : CURL_STATICLIB
  • on the Search Directories - Compiler : include tab - relative / absolute path to headings ( .h ) libraries
  • tab Search Directories - Linker : lib - relative / absolute path to libs ( .a files) of libraries
  • Linker settings - Link libraries : curl , ssl , crypto , ssh2 , nghttp2 , z , ws2_32 , winmm , wldap32 , crypt32 - link libraries. It is very important to follow the order in which libraries will link!

Here, in fact, everything, you can collect:

 gcc.exe -Wall -O2 -DCURL_STATICLIB -std=c99 -m32 --static -static-libgcc -Iinclude -IC:\dev\mingw-w64\mingw32\i686-w64-mingw32\include -c B:\cb_curl_static\main.c -o obj\Release\main.o gcc.exe -Llib -LC:\dev\mingw-w64\mingw32\i686-w64-mingw32\lib -o bin\Release\cb_curl_static.exe obj\Release\main.o -s -m32 --static -static-libgcc -lcurl -lssl -lcrypto -lssh2 -lnghttp2 -lz -lws2_32 -lwinmm -lwldap32 -lcrypt32 Output file is bin\Release\cb_curl_static.exe with size 2.68 MB 

As a result, a rather large exe file was obtained, but it depends only on the system libraries.

  • And if, for example, I don’t need any support, then the crypto probably disappears too, will the weight decrease? - Corle
  • @Corle Yes, but for this you need to recompile libcurl with disabling ssl , ssh and http2 . - zed