C语言 使用 libcurl 链接程序时未解析的符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4176503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unresolved symbols when linking a program using libcurl
提问by Kyle
I know this is programming questions but I'm just frustrated trying to figure out what I'm doing wrong..
我知道这是编程问题,但我只是很沮丧试图找出我做错了什么..
I'm using visual studio 2010 and followed all the steps here: http://curl.haxx.se/libcurl/c/visual_studio.pdf
我正在使用 Visual Studio 2010 并按照以下所有步骤操作:http: //curl.haxx.se/libcurl/c/visual_studio.pdf
When I try to compile my solution I keep getting this error:
当我尝试编译我的解决方案时,我不断收到此错误:
1>------ Build started: Project: LibCurl, Configuration: Debug Win32 ------
1>LibCurl.obj : error LNK2019: unresolved external symbol __imp__curl_easy_cleanup referenced in function _main
1>LibCurl.obj : error LNK2019: unresolved external symbol __imp__curl_easy_perform referenced in function _main
1>LibCurl.obj : error LNK2019: unresolved external symbol __imp__curl_easy_setopt referenced in function _main
1>LibCurl.obj : error LNK2019: unresolved external symbol __imp__curl_easy_init referenced in function _main
1>C:\Users\Kyle\Documents\Visual Studio 2010\libcurl\VisualStudio\LibCurl\Debug\LibCurl.exe : fatal error LNK1120: 4 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Source:
来源:
// LibCurl.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#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://google.com");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
采纳答案by Willi Ballenthin
Looks like the libraries are not being successfully linked. Ensure the library directory is set to include the full path to the libcurl dll. Also make sure this library is actually added to your project.
看起来库没有成功链接。确保库目录设置为包含 libcurl dll 的完整路径。还要确保该库实际上已添加到您的项目中。
回答by stoiczek
I've been using static version of libcurl, and to link my program against it properly, I had to add definition:
我一直在使用 libcurl 的静态版本,为了将我的程序正确链接到它,我必须添加定义:
CURL_STATICLIB
CURL_STATICLIB
to build configuration of my project.
构建我的项目的配置。
回答by cdonts
Besides defining CURL_STATICLIB, for me it was also necessary to link the following dependencies (including libcurl.libor libcurld.lib):
除了定义CURL_STATICLIB,对我来说还需要链接以下依赖项(包括libcurl.lib或libcurld.lib):
Ws2_32.libWldap32.lib
Ws2_32.libWldap32.lib
回答by wayne
I ran into a similar issue - found that I was referencing the 64-bit location of libcurl.lib. Changed the link directory to the 32-bit location and the project compiled perfectly.
我遇到了类似的问题 - 发现我引用了 libcurl.lib 的 64 位位置。将链接目录更改为32位位置,项目编译完美。
回答by tagoma
I had the same problem. I wrote how I finally was able to make CurlLibworks, here: http://quantcorner.wordpress.com/2012/04/08/using-libcurl-with-visual-c-2010/if you wish to have a look. Good luck!
我有同样的问题。我写了我如何最终使CurlLib工作,在这里:http: //quantcorner.wordpress.com/2012/04/08/using-libcurl-with-visual-c-2010/如果你想看看。祝你好运!
回答by Zsolti
After many ideas and configurations, I solved the problem adding this:
经过许多想法和配置后,我解决了添加此问题的问题:
#pragma comment(lib, "lib/libcurl_a.lib")
#pragma comment(lib, "lib/libcurl_a.lib")
where libcurl_a.libis the name of the curl lib file and libis the folder which contains it.
其中libcurl_a.lib是 curl lib 文件的名称,lib是包含它的文件夹。

