2

我最近使用 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;
}

谢谢!:)

4

2 回答 2

1

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

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

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

于 2011-06-19T04:32:32.267 回答
0

有几种方法可以将 .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,但希望过程是相似的。

于 2011-06-19T06:56:36.887 回答