curl-curl/docs/examples
Viktor Szakats 89043ba906
cmake: drop support for CMake 3.17 and older
Require CMake 3.18 (2020-07-15) or newer, up from 3.7 (2016-11-11)
prior to this patch.

This requirement also applies to the distributed `curl-config.cmake`.

To allow dropping compatibility code maintained for old versions, and to
use features which were unpractical in separate code paths. Also to make
testing, documentation and development easier, CI builds faster due to
CMake performance improvements over time. (e.g. integration tests on
macOS run 8x faster (10 minutes is now under 1.5m) in CI, 2.5x faster on
Windows.)

CMake offers pre-built binaries for major platforms. They work without
an install step, just by unpacking and pointing the cmake command to
them. Making upgrades easy in many cases:
https://cmake.org/download/
https://cmake.org/files/
https://github.com/Kitware/CMake/releases

CMake 3.18 brings these feature as generally available when building or
consuming curl/libcurl:

LTO support, improved performance, `pkg-config` and interface target
support, `OBJECT` target (for faster libcurl builds), modern invocation
with `-S`/`-B` options, better support for custom linker options,
FetchContent, `GnuTLS::GnuTLS` target, `--verbose` and `--install`
options, `CMAKE_GENERATOR` env, last but not least unity mode and Ninja
generator.

For maximum build speed, use:
`-DCMAKE_UNITY_BUILD=ON -DCURL_DROP_UNUSED=ON`

As for deprecations, C++11 is required to build CMake itself, which may
be a limit on some platforms. autotools continues to cover them.

Follow-up to 9bcdfb3809 #20408
Follow-up to a7c974e038 #19902
Follow-up to dfbe035c8b #10161
Discussion: https://github.com/curl/curl/discussions/18704

Closes #20407
2026-03-21 13:24:47 +01:00
..
.checksrc build: tidy up curl-specific fstat calls and stat struct type 2026-02-02 18:57:13 +01:00
.gitignore examples/threaded-ssl: delete in favor of examples/threaded 2025-12-17 00:32:20 +01:00
10-at-a-time.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
adddocsref.pl examples: fix typo in comment 2026-03-19 12:02:10 +01:00
address-scope.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
altsvc.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
anyauthput.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
block_ip.c badwords: rework exceptions, fix many of them 2026-03-12 01:01:16 +01:00
cacertinmem.c examples: drop warning silencers no longer hit 2026-03-12 01:01:16 +01:00
certinfo.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
chkspeed.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
CMakeLists.txt cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
connect-to.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
cookie_interface.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
crawler.c tidy-up: miscellaneous 2026-02-12 14:52:16 +01:00
debug.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
default-scheme.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
ephiperfifo.c badwords: avoid 'simply' 2026-03-10 19:34:06 +01:00
evhiperfifo.c badwords: avoid 'simply' 2026-03-10 19:34:06 +01:00
externalsocket.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
fileupload.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
ftp-delete.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
ftp-wildcard.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
ftpget.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
ftpgetinfo.c clang-tidy: drop redundant casts 2026-02-19 15:27:17 +01:00
ftpgetresp.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
ftpsget.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
ftpupload.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
ftpuploadfrommem.c docs: rename CURLcode variables to 'result' 2025-12-17 08:55:12 +01:00
ftpuploadresume.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
getinfo.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
getinmemory.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
getredirect.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
getreferrer.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
ghiper.c badwords: avoid 'simply' 2026-03-10 19:34:06 +01:00
headerapi.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
hiperfifo.c badwords: avoid 'simply' 2026-03-10 19:34:06 +01:00
hsts-preload.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
htmltidy.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
htmltitle.cpp docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
http2-download.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
http2-pushinmemory.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
http2-serverpush.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
http2-upload.c badwords: rework exceptions, fix many of them 2026-03-12 01:01:16 +01:00
http3-present.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
http3.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
http-options.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
http-post.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
httpcustomheader.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
httpput-postfields.c badwords: rework exceptions, fix many of them 2026-03-12 01:01:16 +01:00
httpput.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
https.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-append.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
imap-authzid.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-copy.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-create.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
imap-delete.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
imap-examine.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
imap-fetch.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-list.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-lsub.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
imap-multi.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-noop.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
imap-search.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
imap-ssl.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-store.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-tls.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
interface.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
ipv6.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
keepalive.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
localport.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
log_failed_transfers.c badwords: prefer 'null-terminated' 2026-03-18 11:40:13 +01:00
Makefile.am cmake: support building some complicated examples, build them in CI 2025-10-07 19:09:02 +02:00
Makefile.example Makefile.example: make default options more likely to work 2025-10-20 13:52:58 +02:00
Makefile.inc examples/threaded-ssl: delete in favor of examples/threaded 2025-12-17 00:32:20 +01:00
maxconnects.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
multi-app.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
multi-debugcallback.c badwords: avoid 'simply' 2026-03-10 19:34:06 +01:00
multi-double.c badwords: avoid 'simply' 2026-03-10 19:34:06 +01:00
multi-event.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
multi-formadd.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
multi-legacy.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
multi-post.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
multi-single.c badwords: avoid 'simply' 2026-03-10 19:34:06 +01:00
multi-uv.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
netrc.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
parseurl.c examples: tidy-up headers and includes 2025-11-18 02:05:07 +01:00
persistent.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-authzid.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-dele.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-list.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-multi.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-noop.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
pop3-retr.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-ssl.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-stat.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
pop3-tls.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-top.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
pop3-uidl.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
post-callback.c docs: rename CURLcode variables to 'result' 2025-12-17 08:55:12 +01:00
postinmemory.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
postit2-formadd.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
postit2.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
progressfunc.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
protofeats.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
range.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
README.md stop using the word 'just' 2026-03-03 15:30:22 +01:00
resolve.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
rtsp-options.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
sendrecv.c gcc: guard #pragma diagnostic in core code for <4.6, disable picky warnings 2026-03-18 11:33:37 +01:00
sepheaders.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
sessioninfo.c tidy-up: miscellaneous 2026-02-12 14:52:16 +01:00
sftpget.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
sftpuploadresume.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
shared-connection-cache.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
simple.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
simplepost.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
simplessl.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
smooth-gtk-thread.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
smtp-authzid.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
smtp-expn.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
smtp-mail.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
smtp-mime.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
smtp-multi.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
smtp-ssl.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
smtp-tls.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
smtp-vrfy.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
sslbackend.c build: use more const 2026-02-02 12:32:49 +01:00
synctime.c synctime: fix off-by-one read and write to a read-only buffer (Windows) 2026-03-19 11:17:17 +01:00
threaded.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
unixsocket.c tidy-up: miscellaneous 2026-02-12 14:52:16 +01:00
url2file.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
urlapi.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
usercertinmem.c examples: drop warning silencers no longer hit 2026-03-12 01:01:16 +01:00
version-check.pl tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
websocket-cb.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
websocket-updown.c tidy-up: miscellaneous 2026-02-12 14:52:16 +01:00
websocket.c examples/websocket: fix to sleep more on Windows 2026-03-18 11:37:15 +01:00
xmlstream.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00

libcurl examples

This directory is for libcurl programming examples. They are meant to show some simple steps on how you can build your own application to take full advantage of libcurl.

If you end up with other small but still useful example sources, please mail them for submission in future packages and on the website.

Building

The Makefile.example is an example Makefile that could be used to build these examples. Edit the file according to your system and requirements first.

Most examples should build fine using a command line like this:

`curl-config --cc --cflags --libs` -o example-my example.c

Some compilers do not like having the arguments in this order but instead want you do reorganize them like:

`curl-config --cc` -o example-my example.c `curl-config --cflags --libs`

Please do not use the curl.se site as a test target for your libcurl applications/experiments. Even if some of the examples use that site as a URL at some places, it does not mean that the URLs work or that we expect you to actually torture our website with your tests. Thanks.

Examples

Each example source code file is designed to be and work stand-alone and rather self-explanatory. The examples may at times lack the level of error checks you need in a real world, but that is then only for the sake of readability: to make the code smaller and easier to follow.