FreeBSD初心者運用日記 このページをアンテナに追加

 | 

2007-11-16

[]メモ 08:07 メモ - FreeBSD初心者運用日記 を含むブックマーク はてなブックマーク - メモ - FreeBSD初心者運用日記 メモ - FreeBSD初心者運用日記 のブックマークコメント

  • ソース作成
$ cat hoge.c
#include <stdio.h>
#include <math.h>

int main() {
        double rad;
        for(rad=0;
        rad < 3.1;
        rad += 0.1) printf("sin(%f) = %f\n", rad, sin(rad));
        return;
}
$ gcc hoge.c
/var/tmp//cc86EJaS.o(.text+0x4d): In function `main':
: undefined reference to `sin'
  • ライブラリ
/usr/lib$ nm libm.a | grep sin
w_sinhf.o:
         U __ieee754_sinhf
00000000 T sinhf
w_sinh.o:
         U __ieee754_sinh
00000000 T sinh
w_asinf.o:
         U __ieee754_asinf
00000000 T asinf
w_asin.o:
         U __ieee754_asin
00000000 T asin
s_asinhf.o:
00000000 T asinhf
s_asinh.o:
00000000 T asinh
e_sinhf.o:
00000000 T __ieee754_sinhf
e_sinh.o:
00000000 T __ieee754_sinh
         U sin
         U sinf
         U sin
         U sinf
         U sin
e_asinf.o:
00000000 T __ieee754_asinf
e_asin.o:
00000000 T __ieee754_asin
         U sin
s_sin.o:
0000004c T sin
s_sinf.o:
         U __kernel_sinf
00000000 T sinf
         U __kernel_sinf
         U __kernel_sinf
00000000 t sin_pif
         U __kernel_sin
00000000 t sin_pi
k_sinf.o:
00000000 T __kernel_sinf
k_sin.o:
00000000 T __kernel_sin

  • lオプションつけて、再gcc
$ gcc hoge.c -lm

実行

>|sh|

$ ./a.out

sin(0.000000) = 0.000000

sin(0.100000) = 0.099833

sin(0.200000) = 0.198669

sin(0.300000) = 0.295520

sin(0.400000) = 0.389418

sin(0.500000) = 0.479426

sin(0.600000) = 0.564642

sin(0.700000) = 0.644218

sin(0.800000) = 0.717356

sin(0.900000) = 0.783327

sin(1.000000) = 0.841471

sin(1.100000) = 0.891207

sin(1.200000) = 0.932039

sin(1.300000) = 0.963558

sin(1.400000) = 0.985450

sin(1.500000) = 0.997495

sin(1.600000) = 0.999574

sin(1.700000) = 0.991665

sin(1.800000) = 0.973848

sin(1.900000) = 0.946300

sin(2.000000) = 0.909297

sin(2.100000) = 0.863209

sin(2.200000) = 0.808496

sin(2.300000) = 0.745705

sin(2.400000) = 0.675463

sin(2.500000) = 0.598472

sin(2.600000) = 0.515501

sin(2.700000) = 0.427380

sin(2.800000) = 0.334988

sin(2.900000) = 0.239249

||<

 |