【问题标题】:Having issues using the cURL libraries for Dev-C++ in Windows 7在 Windows 7 中使用用于 Dev-C++ 的 cURL 库时遇到问题
【发布时间】:2011-09-18 00:30:51
【问题描述】:

我最近使用 Dev-C++ 安装中包含的 Packman.exe 在 Dev-C++ 中安装了 cURL 库。当我尝试使用#include <curl/curl.h> 时,我没有收到错误,所以我假设它安装正确。但是,当我尝试从 cURL 网站编译示例时,出现以下错误:

[Linker error] undefined reference to _imp__curl_easy_init
[Linker error] undefined reference to _imp__curl_easy_setopt
[Linker error] undefined reference to _imp__curl_easy_perform
[Linker error] undefined reference to _imp__curl_easy_cleanup

我使用的源码如下:

#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
  CURL *curl;
  CURLcode res;
  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
  return 0;
}

谢谢! :)

【问题讨论】:

  • @walker 看看question here。除了您的问题之外的环境设置与该问题完全相同。

标签: c++ curl libcurl dev-c++


【解决方案1】:

使用(编译的)库需要做两件事:

  • 添加#includes 以便编译器知道库。
  • 添加.libs(或.as)以便链接器知道在哪里可以找到已编译库的代码。

您可能错过了后者。不过,我不使用 Dev-C++,所以我不知道如何添加它。

【讨论】:

  • 好的,谢谢。我有一种感觉,那就是问题所在。我想我现在的问题是如何将 .lib 和/或 .a 文件添加到链接器。
【解决方案2】:

有几种方法可以将 .lib 和/或 .a 文件添加到 Dev-C++ 中的链接器:

以下是我在完成boost教程http://www.boost.org/doc/libs/1_46_1/more/getting_started/windows.html#link-your-program-to-a-boost-library时所做的:

  • 项目 > 项目选项 > 目录 > 库目录 - 然后添加 *.a 文件所在的目录。

  • 项目>项目选项>参数>链接器

    -L"C:\Path\To Your\Lib\Files\boost_1_46_1\stage\lib"
    -l-lboost_regex-mgw34-1_46_1
    

我没有使用 libcurl,但希望过程类似。

【讨论】:

    猜你喜欢
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多