프로그램

centos 에서 curl 설치 + 사용

(주)CKBcorp., 2013. 11. 1. 17:30
반응형


linux 에서 program 을 작성할 때, 웹의 데이터를 가져오려 할 경우, curl 을 쓰면 편하다.


curl 은 http, https, ftp 등의 데이터를 다룰 수 있게 해 준다.


헌데.... 설치법을 잘 모르겠어. OTL.


curl 사이트( http://curl.haxx.se/docs/install.html ) 를 뚫어지게 보다가.... 갑자기 생각나서 콘솔에서 yum 을 쳐봤다.


#yum install curl 


만쉐이!! 진행된다!!

그런데, 실제로 curl 사이트에서 예제 파일을 작성해 보면, 컴파일 안됨.

알고보니, curl 은 실행용 binary 가 있고, 개발용 library 가 있는데, 그냥 yum install curl 하면 binary 만 깔리는 거임.

yum install groupinstall curl 해도 안된다.


결론은


#yum install curl-devel


하면 된다.


아래는 curl 에서 가져온, 컴파일 테스트를 위한 hello world 파일이다. ( 출처 : http://curl.haxx.se/libcurl/c/simple.html )



#include <stdio.h>
#include <curl/curl.h>
 
int main(void)
{
  CURL *curl;
  CURLcode res;
 
  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.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;
}


컴파일 할 때는


# gcc curltest.c -lcurl


과 같이 curl 을 추가해 주자.


추가 : 만일 다른 리눅스 버전에서 yum , apt-get 등으로 curl-devel 이 안 되면, 패키지 이름을 이하의 내용으로 시도해 볼 것.

curl-devel

curl-dev

libcurl

libcurl3

libcurl4

libcurl-openssl-dev

libcurl4-openssl-dev


이거 해도 안되면? 나도모름.






 


반응형