'libm'에 해당되는 글 1건

  1. 2010.05.30 libm (math library)
Linux2010. 5. 30. 19:00
libfreetype 테스트용 프로그램을 컴파일 하는데
아래와 같은 문제가 발생을 했다.

$ gcc example1.c -lfreetype
/tmp/cc2ePnil.o: In function `main':
example1.c:(.text+0x278): undefined reference to `cos'
example1.c:(.text+0x2b0): undefined reference to `sin'
example1.c:(.text+0x2e8): undefined reference to `sin'
example1.c:(.text+0x320): undefined reference to `cos'
collect2: ld returned 1 exit status

해결책은 간단하게 gcc -lm 을 하면 되는데,
Perhaps it needs the maths library linked, -lm, as that is where 'cos' will be.
Though that seems a strange thing to be missing.

[링크 : http://computer-yocher.blogspot.com/2010/05/re-sage-devel-sage-441-build-failures.html]

여기서 -l 은 library이고 파일명으로는, lib 접두가 붙게된다.
즉, -lm은 우분투 10.04 기준으로
lrwxrwxrwx 1 root root      14 2010-05-26 21:55 /usr/lib/libm.so -> /lib/libm.so.6

이녀석을 의미하고, cos() sin() tan()을 사용하는 math.h 를 사용할때에는
추가적으로 -lm 옵션을 추가하여 math library를 링크해주어야 한다.

Posted by 구차니