본문 바로가기

Programming/MFC

How to Build and Use Libcurl with VS2015 on Windows

[출처] : https://www.codepool.biz/build-use-libcurl-vs2015-windows.html


아래와 같이 하면 MS VC++의 nmake를 이용해서 libcurl을 빌드할수 있다.


정적 라이브러리

nmake /f Makefile.vc mode=static VC=14 MACHINE=x64 DEBUG=no

동적 라이브러리

nmake /f Makefile.vc mode=dll VC=14 MACHINE=x64 DEBUG=no


윈도우에서 사용하려면 정적 라이브러리로 빌드해서 사용하자.

dll로 해서 적용할 때 정신적인 스트레스가 엄청나다.

만약 static으로 링크를 했는데도 에러가 발생한다면 아마도 아래 내용일 것이다.

error LNK2019: __imp_curl_global_init 외부 기호(참조 위치:

error LNK2019: __imp_curl_global_cleanup 외부 기호(참조 위

error LNK2019: __imp_curl_slist_append 외부 기호(참조 위치

error LNK2019: __imp_curl_slist_free_all 외부 기호(참조 위

error LNK2019: __imp_curl_easy_strerror 외부 기호(참조 위치

error LNK2019: __imp_curl_easy_init 외부 기호(참조 위치: "

error LNK2019: __imp_curl_easy_setopt 외부 기호(참조 위치:

error LNK2019: __imp_curl_easy_perform 외부 기호(참조 위치

atal error LNK1120: 8개의 확인할 수 없는 외부 참조입니다.

/DCRUL_STATICLIB 를 추가한다.

============================================================================


Libcurl is a free, open source library for transferring data. It supports various protocols include FTP, FTPS, HTTP, HTTPS, GOPHER, TFTP, SCP, SFTP, TELNET, DICT, LDAP, LDAPS, FILE, IMAP, SMTP, POP3, RTSP, and RTMP. I’ve been looking for a cross-platform HTTP library for my project, and libcurl seems to be the best choice.

Libcurl Download

The latest curl version is 7.45.0: http://curl.haxx.se/download.html

How to Build and Distribute Libcurl with Visual Studio 2015 on Windows

Run Visual Studio Command Line Tool:

Visual Studio Command Line Tool

Change directory to winbuild.

To distribute your application, you can force nmake to link in the static Microsoft’s C RunTime (CRT) by passing RTLIBCFG=static.:

1
Set RTLIBCFG=static

Then build static libcurl with the following command:

1
nmake /f Makefile.vc mode=static VC=14 MACHINE=x64 DEBUG=no

The generated libraries and header files are located at ../builds.

libcurl build

Create a new win32 project in Visual Studio 2015 and copy all relevant header files and static libraries into the project.

Write a simple test:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "stdafx.h"
#include "libcurl/include/curl/curl.h"
 
#ifdef _DEBUG
#pragma comment(lib, "libcurl/lib/libcurl_a_debug.lib")
#else
#pragma comment(lib, "libcurl/lib/libcurl_a.lib")
#endif
 
int main()
{
    curl_global_init(CURL_GLOBAL_DEFAULT);
    CURL *curl = curl_easy_init();
    if (curl) {
        CURLcode res;
        curl_easy_setopt(curl, CURLOPT_URL, "http://www.dynamsoft.com");
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }
    curl_global_cleanup();
    printf("Press any key to continue\n");
    getchar();
    return 0;
}

When building the project, you may see the error – curl.obj : error LNK2019: unresolved external symbol:

libcurl error

To fix the error, add the macro CRUL_STATICLIB to preprocessor:

curl static lib

Now you can successfully build your project.

One more thing! Do not forget to change Runtime Library to Multi-threaded(/MT):

runtime library mt

Test the curl app with www.dynamsoft.com:

curl test

Source Code

https://github.com/yushulx/libcurl-sample

'Programming > MFC' 카테고리의 다른 글

regsvr32 ax 필터 등록시 문제가 발생한다면...  (0) 2009.07.01
NTDDI_VERSION에 의한 전처리기 문제  (0) 2009.06.10
[DOM with C/C++] 00. MSXML 4.0 SDK 설치하기  (0) 2008.06.18
타이틀바 없애기  (0) 2008.06.10
win32 dll  (0) 2008.05.28