Unresolved symbols when linking a program using libcurl
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
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开发者_Go百科_easy_cleanup(curl);
}
return 0;
}
I've been using static version of libcurl, and to link my program against it properly, I had to add definition:
CURL_STATICLIB
to build configuration of my project.
Besides defining CURL_STATICLIB
, for me it was also necessary to link the following dependencies (including libcurl.lib
or libcurld.lib
):
Ws2_32.lib
Wldap32.lib
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.
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.
I had the same problem. I wrote how I finally was able to make CurlLib works, here: http://quantcorner.wordpress.com/2012/04/08/using-libcurl-with-visual-c-2010/ if you wish to have a look. Good luck!
This worked for me on VS2017 - x86 Release/Debug - MFC Static Library
Open project properties and review the following
C/C++ - Preprocessor - Preprocessor Definitions - Add CURL_STATICLIB
Linker - Input - Additional Dependencies - Add (CTRL+C)
ws2_32.lib
Normaliz.lib
Crypt32.lib
Wldap32.lib
libcurl_a.lib (libcurl_a_debug.lib for debug configuration)
- C/C++ - General - Additional Include Directories - Add include folder to header files
After many ideas and configurations, I solved the problem adding this:
#pragma comment(lib, "lib/libcurl_a.lib")
where libcurl_a.lib
is the name of the curl lib file and lib
is the folder which contains it.
I had the same error, the problem I had was that I built cURL according to this SO answer, which doesn't work if you wish /MT as a runtime library option.
In order to built cURL with respect to /MT and /MTD you have to also execute Set RTLIBCFG=static
before actually building it with the nmake
command in the very same console. Full process of building cURL this way can be found here.
Edit: In case the URL stops working, I will also put the instructions here:
- Download and extract the CUrl source code to a temp directory. http://curl.haxx.se/download.html, in this tutorial we will be using curl-7.37.0
- Open the “Visual Studio Command Prompt (2010)”
- Browse to the Winbuilds folder. \curl-7.37.0\winbuild.
- Type
Set RTLIBCFG=static
into the command prompt and hit enter. This will set up the compiler to build for /MT and /MTd. - Type
nmake /f MakeFile.vc mode=static DEBUG=yes
to build the debug version or - Type
nmake /f MakeFile.vc mode=static DEBUG=no
to build the release versions.
精彩评论