https://everything.curl.dev/

 

README - Everything curl

AaronChen0 on github, alawvt on github, Amin Khoshnood, amnkh on github, Anders Roxell, Angad Gill, Aris (Karim) Merchant, auktis on github, Ben Bodenmiller Ben Peachey, bookofportals on github, Bruno Baguette, Carlton Gibson, Chris DeLuca, Citizen Esosa,

everything.curl.dev

 

curlCode 라는 데이터 타입으로 정의된 어떤 변수가 있었다.

이런 데이터타입은 기존에 없었으므로 모르는게 당연하다.

알아볼 곳이 필요했는데, 이 사이트에서 관련 함수 또한 찾아볼 수 있었다.

 

const CURLcode isError = curl_easy_perform(curlHandle);
if (isError != CURLE_OK) printf("Error in progress that got source file ");
else {		...		}

 

참고로, curlCode는 에러를 위해 만들어진 데이터 타입이며, 참인 경우 curl_OK(=0)이 반환된다.

curl을 perform 하고 이게 잘 수행되었는지 여부를 따지기에 좋은 것 같았다!

 

 

 

1. #ifdef _debug

#ifdef _DEBUG
#pragma comment (lib, "libcurld.lib")
#else
#pragma comment (lib, "libcurl.lib")
#endif

 

cpp 코딩 시, 맨 윗 줄에 선언해두면 디버깅을 할 때 에러가 난 위치를 알려준다.

보통, 메모리 릭이 발생하면 대강 알려주고 마는데.. 이 코드를 사용하면, 어느 위치에서 발생했는지도 알려준다고 함.

 

뭔가 요롷게 알려주는 것 같다......

 

2. #pragma comment

 

#pragma comment (lib, "wldap32.lib")
#pragma comment (lib, "ws2_32.lib")

 

위의 두 코드로 라이브러리를 링크할 수 있다.

이 방법은 매우 명시적이라서 추가적인 주석 없이도 설명이 충분하게 만든다.

 

도움받은 사이트 : https://shaeod.tistory.com/527

 

1. curl lib zip 파일을 다운로드 받는다.

 

홈페이지 우측 메뉴에 올드 릴리즈 들어가면 보이는 화면!

나는 구글링을 하면서 따라했던지라 최신 버전이 아니라 curl 7.65.1 버전을 다운받았다.

curl lib 다운로드 url : https://curl.se/download/

 

curl downloads

 

curl.se

 

2. curl lib zip 파일의 압축을 푼다.

경로를 다음으로 이동하면, curl_all.sln 파일이 있다. 더블클릭해서 열어주기

C:\다운로드한 경로\curl-7.65.1\projects\Windows\VC14
노란색 부분을 잘 체크해서 디버깅, 릴리즈 한번씩 해줬음! (static 선언)

 

3. 에러 없이 빌드에 잘 성공했다면, 이제 빌드한 lib 파일과 include 폴더를 옮겨줄것임!

1) 아래 경로에 들어가서 두 파일을 복사해서 맨 마지막 굵은 표시한 경로에 복사하기!

- C:\다운로드한 경로\curl-7.65.1\build\Win32\VC14\DLL Release에서 libcurl.lib

- C:\다운로드한 경로\curl-7.65.1\build\Win32\VC14\LIB Debug에서 libcurld.lib

- C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib

 

4. 이제 아래 경로의 include 폴더를 복사해서 굵은 표시의 경로에 붙여넣는다.

- C:\다운로드 경로\curl-7.65.1\include

- C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include

 

5. 끝!!! 마지막으로 curl에서 제공하는 테스트 code로 run 해보기~

#define CURL_STATICLIB

#include <stdio.h>
#include <curl/curl.h>

#pragma comment (lib, "wldap32.lib")
#pragma comment (lib, "ws2_32.lib")

#ifdef _DEBUG
#pragma comment (lib, "libcurld.lib")
#else
#pragma comment (lib, "libcurl.lib")
#endif

int main(void) {

	CURL *curl;
	CURLcode res;

	curl = curl_easy_init();
	if (curl) {
		curl_easy_setopt(curl, CURLOPT_URL, "google.com");
		/* example.com is redirected, so we tell libcurl to follow redirection */
		curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

		/* Perform the request, res will get the return code */
		res = curl_easy_perform(curl);
		/* Check for errors */
		if (res != CURLE_OK)
			fprintf(stderr, "curl_easy_perform() failed: %s\n",
				curl_easy_strerror(res));

		/* always cleanup */
		curl_easy_cleanup(curl);
	}
	
	return 0;

}

 

 

+ Recent posts