Search code examples
ccurlcygwinlibcurl

Why is c curl + libcurl library refusing to link correctly under cygwin?


I have been Googling for the past hour or two, and still no solution has surfaced. There are a lot of forum posts, stackoverflow posts, etc but most if not all are not linking the library (like at all).

I am compiling a sample script this one in particular: http://curl.haxx.se/libcurl/c/sepheaders.html

Background

I have used the same method as this to install: link

First way

Compiled using:

gcc -std=c89 -pedantic -Wall file_name -ofile_name.exe -lcurl

Results:

save.c:26:23: fatal error: curl/curl.h: No such file or directory
#include <curl/curl.h>
                   ^
compilation terminated.

Note

It seemed like curl was not getting unpacked or something.

Second Way

Downloading source and placing the curl dir with curl.h in user\include\curl.

I have been using variations of this to compile/build:

gcc -std=c89 -pedantic -Wall file_name -ofile_name.exe -lcurl

Curl library located here C:\cygwin64\usr\include\curl

Results:

/usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lcurl
collect2: error: ld returned 1 exit status

Second Way

Compiled using:

gcc -std=c89 -pedantic -Wall file_name -ofile_name.exe -Lcurl

Results:

/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0xe7): undefined reference to `curl_global_init'
/cygdrive/c/Users/user3624582/[Finished in 0.4s with exit code 1]AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0xe7): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `curl_global_init'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0xec): undefined reference to `curl_easy_init'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0xec): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `curl_easy_init'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x10d): undefined reference to `curl_easy_setopt'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x10d): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `curl_easy_setopt'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x129): undefined reference to `curl_easy_setopt'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x129): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `curl_easy_setopt'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x146): undefined reference to `curl_easy_setopt'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x146): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `curl_easy_setopt'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x173): undefined reference to `curl_easy_cleanup'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x173): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `curl_easy_cleanup'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x1aa): undefined reference to `curl_easy_cleanup'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x1aa): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `curl_easy_cleanup'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x1ce): undefined reference to `curl_easy_setopt'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x1ce): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `curl_easy_setopt'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x1eb): undefined reference to `curl_easy_setopt'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x1eb): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `curl_easy_setopt'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x1f7): undefined reference to `curl_easy_perform'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x1f7): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `curl_easy_perform'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x21b): undefined reference to `curl_easy_cleanup'
/cygdrive/c/Users/user3624582/AppData/Local/Temp/ccHBcDdl.o:save.c:(.text+0x21b): additional relocation overflows omitted from the output

Things tried

Use cygwin to download source (not just binary like before)

Use cygwin to reinstall curl / libcurl

use cygwin to uninstall and install curl / libcurl

I have then tried downloading it from here: http://curl.haxx.se/download.html Towards the bottom of the page for cygwin64.

After a fresh bin download from cygwin: looks like this

Things not yet tried

Crying

Ripping hair out


Solution

  • All paths below are cygwin paths, not Windows paths.

    In the cygwin package manager (normally available as /setup from the shell) select libcurl and libcurl-devel packages. Do not download anything from curl.haxx.se. Cygwin has everything build just right for your environment, and its package manager takes care of dependencies for you.

    Only if you for some reason need packages built by curl.haxx.se (e.g. you absolutely need the latest and greatest version not adopted by cygwin), download them from curl.haxx.se. Do not overwrite files installed by cygwin; instead, put libraries in /usr/local/lib, headers in /usr/local/include, and executables and DLLs in /usr/local/bin. Otherwise cygwin will happily thrash your files next time you update it. Add corresponding -I and -L flags to your compilation command. You are on your own with the DLL search path. You can add /usr/local/bin to PATH, but then you are open to your own private version of DLL hell. You will also have to make sure you are downloading files for the right architecture, and track dependencies by hand. In short, don't do that unless you know exactly what you are doing and why you need it.

    If you use the cygwin package manager, use just -lcurl linker flag. If you download files from curl.haxx.se (don't do that), use -I/usr/local/include for compilation and -L /usr/local/lib for linking, in addition to -lcurl. Note -l and -L are different flags.