为什么c curl + libcurl库拒绝在cygwin下正确链接?

时间:2014-09-07 06:53:26

标签: c curl cygwin libcurl

过去一两个小时我一直在谷歌搜索,但仍然没有出现任何解决方案。有很多论坛帖子,stackoverflow帖子等,但大多数(如果不是全部)都没有链接库(就像所有)。

我正在编写一个示例脚本,特别是:http://curl.haxx.se/libcurl/c/sepheaders.html

背景

我使用了与此相同的方法来安装:link

第一种方式

使用编译:

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

结果:

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

注意

好像卷曲没有得到解压缩或什么的。

第二种方式

下载源代码并将curl dir与curl.h放在user \ include \ curl。

我一直在使用它的变体来编译/构建:

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

卷曲库位于此处C:\ cygwin64 \ usr \ include \ curl

结果:

/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

第二种方式

使用编译:

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

结果:

/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

尝试过的事情

使用cygwin下载源代码(不仅仅是以前的二进制文件)

使用cygwin重新安装curl / libcurl

使用cygwin卸载并安装curl / libcurl

然后我尝试从这里下载它:http://curl.haxx.se/download.html在cygwin64的页面底部。

从cygwin下载新的bin后:looks like this

尚未尝试的事情

哭泣

撕掉头发

1 个答案:

答案 0 :(得分:4)

以下所有路径均为cygwin路径,而非Windows路径。

在cygwin包管理器中(通常从shell /setup获得)选择libcurllibcurl-devel包。不要从curl.haxx.se下载任何内容。 Cygwin的所有内容都适合您的环境,它的包管理器会为您处理依赖关系。

只有当您出于某种原因需要curl.haxx.se构建的软件包时(例如,您绝对需要cygwin未采用的最新版本),请从curl.haxx.se下载它们。 覆盖cygwin安装的文件;相反,将库放在/usr/local/lib中,/usr/local/include中的标头,以及/usr/local/bin中的可执行文件和DLL。否则,cygwin会在您下次更新时愉快地捶打您的文件。将相应的-I-L标志添加到编译命令中。您可以使用DLL搜索路径。您可以将/usr/local/bin添加到PATH,但随后您将对自己的私有版DLL地址开放。您还必须确保为正确的体系结构下载文件,并手动跟踪依赖性。简而言之,除非你确切知道自己在做什么以及为什么需要它,否则不要这样做。

如果您使用cygwin包管理器,请仅使用-lcurl链接器标志。如果您从curl.haxx.se下载文件(请勿这样做),除-I/usr/local/include外,请使用-L /usr/local/lib进行编译,-lcurl进行链接。注意-l-L是不同的标记。