[해결] libcurl 라이브러리 사용시..링크 오류

liush79의 이미지

curl 라이브러리를 정적 링크 시켰더니..

stringprep_check_version'
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libcurl.a(url.o): In function `fix_hostname':
(.text+0x3b5): undefined reference to `idna_to_ascii_lz'
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libcurl.a(url.o): In function `fix_hostname':
(.text+0x3bc): undefined reference to `stringprep_locale_charset'
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libcurl.a(url.o): In function `fix_hostname':
(.text+0x3f8): undefined reference to `idna_to_unicode_lzlz'
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libcurl.a(url.o): In function `fix_hostname':
(.text+0x459): undefined reference to `tld_check_lz'
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libcurl.a(url.o): In function `fix_hostname':
(.text+0x471): undefined reference to `idn_free'
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libcurl.a(url.o): In function `fix_hostname':
(.text+0x47b): undefined reference to `tld_strerror'
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../libcurl.a(url.o): In function `fix_hostname':
(.text+0x4b1): undefined reference to `tld_strerror'
.........
생략..

이런 링크오류가 나네요..

-lcurl -lidn

idn 라이브러리도 필요하다는 거 같아서
위처럼 했는데..

음 밥먹고 와서

다시 해봐야겟네요..

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

밥먹고 다시 테스트중인데..

-static 이 문제네요

-static 빼면 오류 없이 컴파일 잘 되네요
다른 라이브러리 때문에 -static 을 줘야 합니다.

이걸 어찌 해결 해야 할까요 ?

static 버전이 따로 있을라나..

mirr187의 이미지

header file이 누락된거 같네요...

idna.h stringprep.h tld.h

확인해보시기를...

liush79의 이미지

소스 내용은

#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
 
static size_t curl_callback( void *ptr, size_t size, size_t nmemb, void *stream);
 
int main(int argc, char* argv[])
{
	CURL *curl;
	CURLcode res;
	char ret_val[256] = {0,};
	char szUrl[2048] = {0,};
 
	sprintf(szUrl, "http://localhost/test.php");
 
 
	curl = curl_easy_init();
	if(curl) {
		curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_callback);
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, ret_val);
		curl_easy_setopt(curl, CURLOPT_URL, szUrl);
		res = curl_easy_perform(curl);
 
		printf("msg = %s\n", ret_val);
 
		curl_easy_cleanup(curl);
	}
 
	return 0;
}
 
static size_t curl_callback( void *ptr, size_t size, size_t nmemb, void *stream)
{
	if( strlen((char*)ptr) > 256 )
		strncpy((char*)stream, (char*)ptr, 255);
	else
		strcpy((char*)stream, (char*)ptr);
 
	return size * nmemb;
}

include 코드가 안나오네요 ..
stdio.h
string.h
curl/curl.h

이렇습니다.

해당 파일3개는 모두 /usr/include 안에 존재 합니다.

아니면 소스에.. 인클루드 하라는 것인가요 ?
idn 헤더 파일은 제가 인클루드 안해도 되는거 같습니다.

IsExist의 이미지

libidn을 static 버전으로 설치하고 libidn.a 를 직접 링크 해보세요.

--------
간디가 말한 우리를 파괴시키는 7가지 요소

첫째, 노동 없는 부(富)/둘째, 양심 없는 쾌락
셋째, 인격 없는 지! 식/넷째, 윤리 없는 비지니스

이익추구를 위해서라면..

다섯째, 인성(人性)없는 과학
여섯째, 희생 없는 종교/일곱째, 신념 없는 정치

---------
간디가 말한 우리를 파괴시키는 7가지 요소

첫째, 노동 없는 부(富)/둘째, 양심 없는 쾌락
셋째, 인격 없는 지! 식/넷째, 윤리 없는 비지니스

이익추구를 위해서라면..

다섯째, 인성(人性)없는 과학
여섯째, 희생 없는 종교/일곱째, 신념 없는 정치

liush79의 이미지

방금 해결 해서 해결 했다고 리플달러 왔는데

답변을 해주셨네요..

전 조금 다르게 해결 했네요 ..

libcurl configure 옵션을
./configure --disable-shared --disable-ldap --disable-ldaps --without-ssl

이렇게 주고..(에러나는요소를 빼버렸습니다-_-)

컴파일 시에는
g++ -o curltest curltest.cpp -lcurl -lidn -ldl -lz -static

이런식으로 해결 했네요 ..