Key Dependencies for Building curl: A Complete Guide to Optional and Required Libraries
Building curl requires a TLS backend (OpenSSL, GnuTLS, mbedTLS, WolfSSL, Rustls, or Schannel on Windows) and standard build tools, while dozens of optional libraries enable compression, asynchronous DNS, SSH, and modern protocols like HTTP/2 and HTTP/3.
The curl/curl repository provides a modular build system that compiles across platforms from embedded devices to Windows servers. Understanding the key dependencies for building curl ensures you link only necessary features while maintaining security through proper TLS integration. Whether using CMake or autotools, the build system detects libraries via find_package calls in CMakeLists.txt or pkg-config checks, adding found targets to the CURL_LIBS link line.
Required: TLS/SSL Backends
A functional curl build must include a TLS library to handle HTTPS and other encrypted protocols. The source code in CMakeLists.txt (lines 823‑950) searches for these backends using find_package calls.
Available TLS options:
- OpenSSL — The default choice on most Unix-like systems (
find_package(OpenSSL)) - GnuTLS — Alternative open-source implementation (
find_package(GnuTLS)) - mbedTLS — Lightweight option for embedded environments (
find_package(MbedTLS)) - WolfSSL — Optimized for size and speed (
find_package(WolfSSL)) - Rustls — Modern Rust-based TLS library (
find_package(Rustls)) - Schannel — Native Windows security package (automatic on Windows builds)
If multiple TLS libraries are present, OpenSSL takes precedence unless explicitly configured otherwise.
Compression Libraries
While optional, zlib is enabled by default in most builds and handles Content-Encoding: gzip and deflate. The detection occurs in CMakeLists.txt lines 981‑1002 via the curl_dependency_option macro defined in CMake/Macros.cmake.
Compression options:
- zlib — Standard gzip/deflate compression (
CURL_ZLIB) - Brotli — Modern compression algorithm (
CURL_BROTLI) - zstd — Facebook's Zstandard compression (
CURL_ZSTD)
When enabled, these libraries attach to CURL_LIBS and provide automatic decompression of HTTP responses.
Protocol Extensions: HTTP/2 and HTTP/3
Modern protocol support requires specific third-party libraries that implement the underlying framing and transport layers.
HTTP/2 support requires nghttp2 (find_package(NGHTTP2 MODULE) at line 1123).
HTTP/3 and QUIC require more specific dependencies:
- nghttp3 — HTTP/3 implementation (
find_package(NGHTTP3 MODULE)at line 1163) - ngtcp2 — QUIC transport (
find_package(NGTCP2 MODULE)at lines 1137‑1157) - quiche — Apple's QUIC implementation (
find_package(Quiche MODULE REQUIRED)at line 1175)
These are typically disabled by default and must be explicitly enabled during configuration.
Network and Transport Helpers
Several libraries extend curl's networking capabilities beyond standard system calls.
Asynchronous DNS via c-ares (find_package(Cares MODULE REQUIRED) at line 412) prevents blocking during hostname resolution, crucial for high-performance applications.
Protocol-specific libraries:
- libssh2 or libssh — SFTP and SCP support (
find_package(Libssh2),find_package(Libssh)) - libldap — LDAP directory queries (
find_package(LDAP)) - libpsl — Public Suffix List validation for cookie domain handling (
find_package(Libpsl)) - libidn2 — Internationalized domain name handling (
find_package(Libidn2 MODULE)at line 1279)
Authentication and Security Extensions
Additional libraries in CMakeLists.txt (lines 1302‑1367) provide enterprise authentication features:
- libgsasl — GNU SASL implementation
- GSS — Kerberos/SPNEGO authentication
- libbacktrace — Stack trace generation for debugging
- libuv — Event loop integration for the multi-API
Build System Requirements
The classic autotools flow requires specific development tools documented in docs/INSTALL.md (line 34). You need autoconf, automake, libtool, GNU m4, and pkg-config to run ./configure.
For CMake builds, the system uses the curl_dependency_option macro in CMake/Macros.cmake to create cache options (like CURL_USE_OPENSSL) and attempts detection automatically. If a library is found, its imported target (e.g., OpenSSL::SSL) links into the final binary.
Platform-specific notes:
- Windows: Requires Visual Studio, MinGW-w64, or Cygwin with specific CRT settings (
docs/INSTALL.mdlines 9‑16) - Cygwin: Package list documented at lines 56‑69 of
docs/INSTALL.md
Configuration Examples
Minimal Build with OpenSSL and zlib
Using autotools:
./configure --with-openssl --with-zlib
make
sudo make install
Using CMake:
cmake -B build -DCURL_USE_OPENSSL=ON -DCURL_ZLIB=ON .
cmake --build build
sudo cmake --install build
Feature-Rich Build with HTTP/2 and Async DNS
Using autotools:
./configure --with-openssl --with-nghttp2 --with-ares --with-brotli
make && sudo make install
Using CMake:
cmake -B build \
-DCURL_USE_OPENSSL=ON \
-DCURL_HTTP2=ON \
-DENABLE_ARES=ON \
-DCURL_BROTLI=ON
cmake --build build && sudo cmake --install build
Windows Visual Studio Build
git clone https://github.com/curl/curl.git
cd curl
mkdir build && cd build
cmake .. -G "Visual Studio 17 2022" -A x64 ^
-DCURL_STATIC_CRT=OFF ^
-DCURL_USE_OPENSSL=ON ^
-DCURL_ZLIB=ON
cmake --build . --config Release
The -DCURL_STATIC_CRT=OFF flag avoids static CRT linkage, which is discouraged for DLL builds per docs/INSTALL.md.
Summary
- TLS is mandatory: Every curl build requires OpenSSL, GnuTLS, mbedTLS, WolfSSL, Rustls, or Schannel (Windows) as implemented in
CMakeLists.txtlines 823‑950. - zlib is standard: While technically optional, compression support via zlib is expected in most deployments.
- Protocols require specific libraries: HTTP/2 needs nghttp2, HTTP/3 requires nghttp3 and ngtcp2 or quiche, and asynchronous DNS requires c-ares.
- Build tools differ by system: Autotools requires autoconf/automake/libtool, while CMake uses the
curl_dependency_optionmacro inCMake/Macros.cmaketo detect dependencies. - All optional features are configurable: Use
--with-<library>or--without-<library>for autotools, or-DCURL_USE_<LIBRARY>=ON/OFFfor CMake.
Frequently Asked Questions
Can I build curl without any TLS library?
No, curl requires a TLS backend to support HTTPS and other encrypted protocols. Attempting to build without one (using --without-ssl or equivalent) produces a limited binary that cannot handle encrypted connections. According to the source code in CMakeLists.txt, the build system searches for OpenSSL, GnuTLS, mbedTLS, WolfSSL, Rustls, or Schannel, and at least one must be present for a standard build.
What is the difference between c-ares and the default DNS resolver?
c-ares provides asynchronous, non-blocking DNS resolution, while the default uses the system's synchronous getaddrinfo call. When you enable c-ares (--with-ares or -DENABLE_ARES=ON), curl can perform DNS lookups in the background without blocking other transfers. This is essential for high-performance applications using the multi-interface.
How do I enable HTTP/3 support in my curl build?
HTTP/3 support requires specific QUIC libraries. You must build with nghttp3 and either ngtcp2 or quiche. In CMake, enable -DUSE_NGTCP2=ON or -DUSE_QUICHE=ON alongside -DUSE_NGHTTP3=ON. These dependencies are detected in CMakeLists.txt at lines 1137‑1175. Note that HTTP/3 support is considered experimental in some curl versions and requires compatible server infrastructure.
Can I statically link all dependencies when building curl?
Yes, static linking is supported but requires careful management of dependency chains. When using CMake, set -DBUILD_SHARED_LIBS=OFF and ensure static versions of OpenSSL, zlib, and other libraries are available in your toolchain. On Windows, avoid -DCURL_STATIC_CRT=OFF if you want dynamic CRT linkage. The autotools build supports --disable-shared to produce static binaries, though you must ensure all downstream libraries are also available as static archives.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →