VS2013 (via Visual Studio Tools) compile libcurl library

Reference: https://blog.csdn.net/cym1990/article/details/79851039

Compile

  1. Download the source code from https://github.com/curl/curl , here we choose curl-7_65_2;
  2. Enter the downloaded source code folder and double-click the buildconf.bat file to run;
  3. Enter the "winbuild" folder in the curl folder and copy its folder path, for example: E:\xxxxxxxxxx\curl-curl-7_65_2\winbuild;
  4. Open the start menu, in Visual Studio Tools under vs2013, (to compile 64-bit) select "x64 native tool command prompt for VS 2017", (to compile 32-bit) select "x86 for VS 2017 Native tool command prompt", right click to run as administrator, here we choose to compile 32-bit;
  5. Enter the vs2013 x86 native tool into the command line, enter the command: cd /d E:\xxxxxxxxxx\curl-curl-7_65_2\winbuild, enter this directory;
  6. Enter the compilation command: nmake /f Makefile.vc mode=static VC=12 MACHINE=x86 and press Enter and wait for the compilation to be completed;
  7. After the compilation is complete, the corresponding library files are generated in the build directory. The library files include three directories including include, lib, and bin.

Note, here we are compiling a 32-bit static library, release version.    

  • To compile the dynamic library, change "mode=static" to "mode=dll". 
  • If you need to compile the debug version, change "DEBUG=no" to "DEBUG=yes". If the DEBUG item is not set, the default is the release version.
  • If you need to compile the 64-bit version, change "MACHINE=x86" to "MACHINE=x64". 
  • If you want to use other versions of Visual Studio to compile, the number after "VC=" should be changed to this Visual Studio version.

New project for testing

Create an empty project and add the following code:

#include "include/curl/curl.h"  
 
int main()  
{  
    curl_easy_init();  
    return 0;  
}  

And add the "include" folder and "lib" folder in the generated folder to the project.

Add the static library "libcurl_a.lib" to the project. 

Since we compile libcurl statically, we need to add "CURL_STATICLIB" to the preprocessing of the project. 

 

Possible errors and solutions:

Error 1 : Unresolved external symbol __imp__curl_easy_init

Libcurl is not linked to the program, and the function entry cannot be found.

Solution: Open the project properties, configure the properties-C/C++-Preprocessor-Preprocessor definition-Open the drop-down box-Edit-Enter CURL_STATICLIB in the text box-Save

(Or #define CURL_STATICLIB in curl.h)

Error 2 : Unresolved external symbol __imp__CertOpenStore@20

Solution: Add: Crypt32.lib in project properties-linker-input-additional dependencies.

Error 3 : Unresolved external symbol __imp__IdnToAscii@20

Solution: add: Normaliz.lib in the project properties-linker-input-additional dependencies.

Error 4 : Unresolved external symbol __imp__WSAStartup@8

Unresolved external symbol __imp__ldap_init

Solution: Add: ws2_32.lib, wldap32.lib in the project properties-linker-input-additional dependencies.

Reference: https://blog.csdn.net/px41834/article/details/81627170

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/lt4959/article/details/96475906