It might be even easier this way:
$ curl https://ifconfig.me --libcurl ip_fetcher.c
$ make LDFLAGS=-lcurl ip_fetcher
$ ./ip_fetcher
(I just find make a heck of a lot easier than running direct cc commands)