LibCurl - Release Static Lib linking problems

2019-06-05 09:03发布

问题:

I have been at this for some time now. I hope someone can tell me what I am doing wrong.

These are the steps I have taken so far:

-Downloaded the latest version of cURL (7.21.7).

-Opened the solution in Visual Studio 2010 using the vc6curl.dsw and converted the projects to VS2010.

-Set the libcurl project configuration to "release" and built. Build succeeded.A folder called "LIB-Release" is created. It contains several obj files and the "libcurl.lib" file resides here as well.

Test Application:

-In the project's settings I pointed the compiler to the curl includes (headers).

C/C++ >> General >> Additional Include Directories

-Added "CURL_STATICLIB" to the preprocessor definitions

C/C++ >> Preprocessor Definitions

-Added the path to the "libcurl.lib" folder in my linker additional library dependencies

Link >> General >> Additional Library Directories

-Added "libcurl.lib" to my linker additional dependencies

Link >> Input >> Additional Dependencies

-Set my projects configuration to "Realease" and hit build!

I get 42 unresolved externals errors:

Error 65 error LNK1120: 42 unresolved externals C:\Users\Nick\Documents\Visual Studio 2010\Projects\curl_static_lib\Release\curl_static_lib.exe curl_static_lib Error 61 error LNK2001: unresolved external symbol ___WSAFDIsSet@8 C:\Users\Nick\Documents\Visual Studio 2010\Projects\curl_static_lib\curl_static_lib\libcurl.lib(select.obj) curl_static_lib Error 59 error LNK2001: unresolved external symbol _imp_accept@12 C:\Users\Nick\Documents\Visual Studio 2010\Projects\curl_static_lib\curl_static_lib\libcurl.lib(ftp.obj) curl_static_lib Error 46 error LNK2001: unresolved external symbol _imp_ber_free C:\Users\Nick\Documents\Visual Studio 2010\Projects\curl_static_lib\curl_static_lib\libcurl.lib(ldap.obj) curl_static_lib Error 26 error LNK2001: unresolved external symbol _imp_bind@12 C:\Users\Nick\Documents\Visual Studio 2010\Projects\curl_static_lib\curl_static_lib\libcurl.lib(connect.obj) curl_static_lib

I have tried building using the "Debug" configuration as well. Can someone please tell me where I am going wrong?

回答1:

The best way to build CURL for windows is to use NMake with provided Makefiles. You can

  1. Modify Makefile in root folder of CURL to set VC version you use and then run nmake vc-all (or choose any other VC target suitable for you). Check "Win32" section of ./docs/INSTALL file.

  2. Use Makefile.vc from ./winbuild folder. Check ./winbuild/BUILD.WINDOWS.txt on how to use it.



回答2:

These errors mean that there are functions that libcurl uses that are not in any of the import libraries specified in your linker config.

Sounds like at least the sockets import lib (ws2_32.lib) should be there.

Note that if you compile libcurl as a DLL then all the import libraries are specified as part of the linking of the DLL, so your application then does not need to import all these libraries and just needs to link against the curl import lib. The fact that you chose to compile curl as a static lib makes the curl code part of your application so all the support libs must be provided in your app's linker config.