맥 OS X 에서 tr1 사용하기
글쓴이: parkon / 작성시간: 토, 2013/04/27 - 9:19오후
안녕하세요,
사실 설치 및 활용란에 질문글 올렸는데 무플이라 실례를 무릎쓰고 여기 다시 올립니다.
저도 잘은 모르지만 C++0x인가 boost인가 암튼 그기에서
흔히 쓰이는 특수함수 (베셀 함수, 등등)들이 포함되어 리눅스에서 잘 쓰고 있습니다.
그 중 하나인 exponential integral Ei 함수를 쓰고 싶은데요 (함수명이 expint임),
리눅스에서 아래의 코드가 잘 돌아 갑니다.
#include <stdio.h>
#include <cmath>
#include <tr1/math.h>
int main()
{
double x = -3;
double y = std::tr1::expint(x);
printf("Ei(%f) = %f\n", x, y);
return 0;
}하지만 OS X 깔린 제 맥 노트북에선
$ c++ test.cxx
test.cxx:11:25: error: no member named 'expint' in namespace 'std::tr1'
double y = std::tr1::expint(x);
~~~~~~~~~~^
1 error generated.
$ g++ test.cxx
test.cxx: In function ‘int main()’:
test.cxx:11: error: ‘expint’ is not a member of ‘std::tr1’이런 에러를 만듭니다.
마구 찾아 보니 boost를 깔면 된다는 글을 보고
brew install boost
하나 뭔가 깔리긴 하는데 여전히 안되어 디렉토리 검색해보니
/usr/local/Cellar/boost/1.52.0/include/boost/tr1$
요 디렉토리에 cmath.hpp에 expint가 들어가 있더군요.
그래서 코드를 다음과 같이 수정해 봤습니다:
#include <stdio.h>
#include <cmath>
//#include <tr1/math.h>
#include <boost/tr1/cmath.hpp>
int main()
{
double x = -3;
double y = std::tr1::expint(x);
printf("Ei(%f) = %f\n", x, y);
return 0;
}이렇게 했더니
$ g++ test.cxx
Undefined symbols for architecture x86_64:
"_boost_expint", referenced from:
boost::math::tr1::expint(double)in ccZ5PXe9.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status이런 에러가 뜹니다.
뭔가 링크 에러같긴 한데 지식이 짧아 여기서 어떻게 나갈지 잘 모르겠군요.
구글링 해 봐도 잘 모르겠고요.
간단한 힌트나 추측이라도 주시면 감사하겠습니다.
Forums:


이런, 프로그래밍 QnA에 올린다는게 다시 여기 설치
이런, 프로그래밍 QnA에 올린다는게
다시 여기 설치 및 활용 QnA에 올렸군요...,
맨붕이 오는 듯...
게시판 어지럽혀서 정말 죄송합니다...
g++ -lboost_math_tr1 test.cxx
g++ -lboost_math_tr1 test.cxx
답변 감사합니다. 제가 해보니 ld: library
답변 감사합니다.
제가 해보니
ld: library not found for -lboost_math_tr1
이렇게 나오는 데
뭔가 설정같은 걸 더 잡아 줘야 하나요 ?
g++ -lboost_math_tr1-mt
g++ -lboost_math_tr1-mt test.cxx
이렇게 하니 기적처럼 잘 되는군요,
와우, 정말 감사합니다... ^^
댓글 달기