43

I'm using visual studio 2010 and followed all the steps here.

When I try to compile my solution:

// 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;
}

...I keep getting these errors:

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 ==========

What am I doing wrong?

2
  • make sure you did steps 4.3.2 and 4.3.3 from the linked pdf. You're getting a linker error, which means it's not linking with the file libcurl.lib. Commented Nov 14, 2010 at 8:43
  • Thanks Jesse. I will redo the steps slower and see why it's not being linked. Thanks for the help! Commented Nov 14, 2010 at 9:02

9 Answers 9

115

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.

Sign up to request clarification or add additional context in comments.

6 Comments

This is probably one of the common problems: if you are using libcurl as a STATIC library you need to define CURL_STATICLIB not only in the curl project, but also in the project where you want to use it.
Another interesting point I've just met: You can define it in main project and forget to mention in another vcproj you are using.
thank you so much. go to vc++ project settings | c++ | preprocessor and add the CURL_STATICLIB to preprocessor definitions and it works
Is it accrual on MSVC only?
this worked as: #define CURL_STATICLIB, but only if I use W32 library... beats me why it does not work for W64; but, mission accomplished, now I move forward, thanks.
|
30

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

2 Comments

I had several more missing dependencies this answer helped me stackoverflow.com/questions/50477484/…
Where did you get the LIB files?
9

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

1 Comment

this helped me. had the crypt32 and normaliz not included.
7

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.

Comments

6

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.

1 Comment

You need to include libcurl.lib, curllib.lib
3

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.

1 Comment

Setting RTLIBCFG=static is not a good idea. ` Typically you shouldn't use that option, and nmake will default to the DLL CRT. RTLIBCFG is rarely used and therefore rarely tested.`
2

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.

1 Comment

Thanks. That worked for me! Added it to one of the header-files. CURL_STATICLIB was not needed in this case, by the way I'm using my self-compiled version of curl 7.70.0 with: curl-7.70.0\winbuild> nmake /f Makefile.vc mode=dll. In this case use: #pragma comment(lib, "lib/libcurl.lib")
0

I had the same error. The problem was that I build the libcurl_a.lib in 32-bit, and my project was in 64-bit. You'll have to use a 64-bit hosted developer command prompt instead of the 32-bit prompt. So instead of opening it via "VS->Tools->Developer Command Prompt", you will have to use the shortcut "x64 Native Tools Command Prompt for VS 2022" from the Windows start menu. See https://learn.microsoft.com/en-us/cpp/build/how-to-enable-a-64-bit-visual-cpp-toolset-on-the-command-line?view=msvc-170

Comments

0

I'd like to add

Secur32.lib

for curl version 8.15.0 compilation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.