맥 OS X 에서 tr1 사용하기

parkon의 이미지

안녕하세요,
사실 설치 및 활용란에 질문글 올렸는데 무플이라 실례를 무릎쓰고 여기 다시 올립니다.

저도 잘은 모르지만 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

이런 에러가 뜹니다.

뭔가 링크 에러같긴 한데 지식이 짧아 여기서 어떻게 나갈지 잘 모르겠군요.
구글링 해 봐도 잘 모르겠고요.

간단한 힌트나 추측이라도 주시면 감사하겠습니다.

parkon의 이미지

이런, 프로그래밍 QnA에 올린다는게
다시 여기 설치 및 활용 QnA에 올렸군요...,
맨붕이 오는 듯...

게시판 어지럽혀서 정말 죄송합니다...

익명 사용자의 이미지

g++ -lboost_math_tr1 test.cxx

parkon의 이미지

답변 감사합니다.
제가 해보니
ld: library not found for -lboost_math_tr1
이렇게 나오는 데
뭔가 설정같은 걸 더 잡아 줘야 하나요 ?

parkon의 이미지

g++ -lboost_math_tr1-mt test.cxx

이렇게 하니 기적처럼 잘 되는군요,
와우, 정말 감사합니다... ^^

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.