简体   繁体   English

如何使用GCC(在Windows上)正确包含libcurl?

[英]How can I include libcurl correctly using GCC (on Windows)?

I'm getting a linker error whenever I #include in my program. 每当在程序中包含#include时,我都会收到链接器错误。 I have downloaded libcurl from haxx.se, compiled libcurl.dll, and added -Icurl to my GCC options when compiling (as well as tried adding a direct path using -L to the dll). 我已经从haxx.se下载libcurl,编译了libcurl.dll,并在编译时将-Icurl添加到了我的GCC选项中(以及尝试使用-L向dll添加直接路径)。 However, I still get the following errors: 但是,我仍然收到以下错误:

undefined reference to `_imp__curl_easy_init'
undefined reference to `_imp__curl_easy_setopt'
undefined reference to `_imp__curl_easy_setopt'
undefined reference to `_imp__curl_easy_perform'
undefined reference to `_imp__curl_easy_strerror'
undefined reference to `_imp__curl_easy_cleanup'

My compile command includes this: 我的编译命令包括:

-Icurl -L"F:/GCCnew/lib/libcurl.dll"

What am I doing wrong? 我究竟做错了什么? I suspect it's something simple but I can't work it out and searching hasn't given me a solution that doesn't use something like Code::blocks. 我怀疑这很简单,但是我无法解决,搜索还没有给我一个不使用Code :: blocks之类的解决方案。

My compile command includes this: 我的编译命令包括:

-Icurl -L"F:/GCCnew/lib/libcurl.dll" -Icurl -L“ F:/GCCnew/lib/libcurl.dll”

If you use mingw gcc, then: 如果使用mingw gcc,则:

  • First, -L must have a folder name, not a library name. 首先, -L必须具有文件夹名称,而不是库名称。
  • Second, there must be '-l' option. 其次,必须有“ -l”选项。 For example -lcurl. 例如-lcurl。
  • Third, -Icurl is irrelevant to your linker error 第三,-Icurl与您的链接器错误无关

So the command to build might look like: 因此,构建命令可能如下所示:

gcc your-file.c -o executable_name -L"F:/GCCnew/lib" -lcurl

Useful links: 有用的链接:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM