attractivechaos / klib

A standalone and lightweight C library
http://attractivechaos.github.io/klib/
MIT License
4.18k stars 556 forks source link

compile error #184

Closed liusuchao closed 2 months ago

liusuchao commented 2 months ago

Hello,

First of all, thank you for creating such a wonderful library that greatly simplifies our application development. It's fantastic!

Shouldn't the makefile be modified? This is my own idea.

kmin_test:kmin_test.c ../kmath.h ../kmath.c
        $(CC) $(CFLAGS) -o $@ kmin_test.c ../kmath.c  -lm //add -lm

Here are my compilation environment details:

Linux 7737b1369220 6.6.32-linuxkit #1 SMP Thu Jun 13 14:13:01 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux
klib version 29445495262cf34f4c3b82d3917ac83f3e1f3f58

Here are the commands I used for compilation:

user@7737b1369220:~/data$ cd klib/
user@7737b1369220:~/data/klib$ ls
LICENSE.txt  cpp          kavl.h    keigen.c  kexpr.h   khmm.c   kmath.h     knhx.h   ksa.c   ksort.h    ksw.h      kurl.h
README.md    kalloc.c     kbit.h    keigen.h  kgraph.h  khmm.h   knetfile.c  kopen.c  kseq.h  kstring.c  kthread.c  kvec.h
bgzf.c       kalloc.h     kbtree.h  ketopt.h  khash.h   klist.h  knetfile.h  krmq.h   kson.c  kstring.h  kthread.h  lua
bgzf.h       kavl-lite.h  kdq.h     kexpr.c   khashl.h  kmath.c  knhx.c      krng.h   kson.h  ksw.c      kurl.c     test
user@7737b1369220:~/data/klib$ cd test/
user@7737b1369220:~/data/klib/test$ make

Here are the logs printed during compilation:

gcc -g -Wall -O2 -I.. -o kmin_test kmin_test.c ../kmath.c  
../kmath.c: In function ‘krf_brent’:
../kmath.c:224:21: warning: ‘e’ may be used uninitialized [-Wmaybe-uninitialized]
  224 |                 if (fabs(e) >= tol1 && fabs(fa) > fabs(fb)) {
      |                     ^~~~~~~
../kmath.c:200:43: note: ‘e’ was declared here
  200 |         double a = x1, b = x2, c = x2, d, e, min1, min2;
      |                                           ^
/usr/bin/ld: /tmp/cca4C0vx.o: in function `kf_lgamma':
/home/user/data/klib/test/../kmath.c:280:(.text+0xcfc): undefined reference to `log'
/usr/bin/ld: /home/user/data/klib/test/../kmath.c:280:(.text+0xd0c): undefined reference to `log'
/usr/bin/ld: /tmp/cca4C0vx.o: in function `_kf_gammap':
/home/user/data/klib/test/../kmath.c:340:(.text+0xd9c): undefined reference to `log'
/usr/bin/ld: /home/user/data/klib/test/../kmath.c:340:(.text+0xdc0): undefined reference to `log'
/usr/bin/ld: /home/user/data/klib/test/../kmath.c:340:(.text+0xdd8): undefined reference to `exp'
/usr/bin/ld: /tmp/cca4C0vx.o: in function `_kf_gammaq':
/home/user/data/klib/test/../kmath.c:361:(.text+0xe84): undefined reference to `log'
/usr/bin/ld: /home/user/data/klib/test/../kmath.c:361:(.text+0xea0): undefined reference to `log'
/usr/bin/ld: /home/user/data/klib/test/../kmath.c:361:(.text+0xeb8): undefined reference to `exp'
/usr/bin/ld: /tmp/cca4C0vx.o: in function `kf_betai_aux':
/home/user/data/klib/test/../kmath.c:403:(.text+0xfc4): undefined reference to `log'
/usr/bin/ld: /home/user/data/klib/test/../kmath.c:403:(.text+0xfdc): undefined reference to `log'
/usr/bin/ld: /home/user/data/klib/test/../kmath.c:403:(.text+0xfe4): undefined reference to `exp'
/usr/bin/ld: /tmp/cca4C0vx.o: in function `kf_erfc':
/home/user/data/klib/test/../kmath.c:307:(.text+0x1044): undefined reference to `exp'
collect2: error: ld returned 1 exit status
make: *** [Makefile:54: kmin_test] Error 1