Cannot open curl/libcurl_a_debug.lib

In my current project I'm using the library libcurl, previously installed by powershell. I'm including it using #include "curl/curl.h" and compiling works but I have a linking error that says:

:LNK1104:cannot open file curl/libcurl_a_debug.lib

I dont have this file. In my current directory i found only libcurl.lib. I already added the path to the directory in Additional library directories and Additional include directories. I'd like to know is any other way to solve this error. In release mode i have an error that linker cannot open file libcurl_a.lib. On the other hand in debug folder i have a libcurl-d.lib file.

Upvotes: 0

Views: 2606

Answers (1)

Barrnet Chou
Barrnet Chou

Reputation: 1923

According to Microsoft Docs, there are several common causes for this issue:

  • The path to your library file may be incorrect, or not wrapped in double-quotes. Or, you may not have specified it to the linker.
  • You may have installed a 32-bit version of the library but you're building for 64 bits, or the other way around.
  • The library may have dependencies on other libraries that aren't installed.

By the way, could you add libcurl.lib in Properties->Linker->Additional Dependencies? If not, you could add it.

You could try to use compiled statements instead of settings.

#ifdef _DEBUG
#pragma comment(lib,"..\\debug\\lib name")
#else
#pragma comment(lib,"..\\release\\lib name")
#endif 

Also, I read the official documentation of curl. There is a description of Windows link errors:

5.7 Link errors when building libcurl on Windows!

You need to make sure that your project, and all the libraries (both static and dynamic) that it links against, are compiled/linked against the same run time library.

This is determined by the /MD, /ML, /MT (and their corresponding /M?d) options to the command line compiler. /MD (linking against MSVCRT dll) seems to be the most commonly used option.

When building an application that uses the static libcurl library, you must add -DCURL_STATICLIB to your CFLAGS. Otherwise the linker will look for dynamic import symbols. If you're using Visual Studio, you need to instead add CURL_STATICLIB in the "Preprocessor Definitions" section.

If you get linker error like "unknown symbol __imp__curl_easy_init ..." you have linked against the wrong (static) library. If you want to use the libcurl.dll and import lib, you don't need any extra CFLAGS, but use one of the import libraries below. These are the libraries produced by the various lib/Makefile.* files:

Target: static lib. import lib for libcurl*.dll.
-----------------------------------------------------------
MingW: libcurl.a libcurldll.a
MSVC (release): libcurl.lib libcurl_imp.lib
MSVC (debug): libcurld.lib libcurld_imp.lib
Borland: libcurl.lib libcurl_imp.lib

I suggest that you could try the method.

Upvotes: 3

Related Questions