samtools
samtools copied to clipboard
Doesn't compile on Mountain Lion
samtools doesn't compile on Mountain Lion. bam_qa.c produces this error
bam_qa.c: In function 'main_qa':
bam_qa.c:88: warning: implicit declaration of function 'getopt'
bam_qa.c:92: error: 'optarg' undeclared (first use in this function)
bam_qa.c:92: error: (Each undeclared identifier is reported only once
bam_qa.c:92: error: for each function it appears in.)
bam_qa.c:96: error: 'optind' undeclared (first use in this function)
make[1]: *** [bam_qa.o] Error 1
make: *** [all-recur] Error 1
This is easily solved with this patch
diff --git a/bam_qa.c b/bam_qa.c
index ef2ea85..16813cb 100644
--- a/bam_qa.c
+++ b/bam_qa.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <unistd.h>
#include "radix.h"
#include "sam.h"
in addition, linking produces this error:
clang -g -Wall -O2 -o samtools bam_tview.o bam_plcmd.o sam_view.o bam_rmdup.o bam_rmdupse.o bam_mate.o bam_stat.o bam_color.o bamtk.o kaln.o bam2bcf.o bam2bcf_indel.o errmod.o sample.o cut_target.o phase.o bam2depth.o bam_qa.o padding.o libbam.a -Lbcftools -lbcf -lcurses -lm -lz
Undefined symbols for architecture x86_64:
"___ks_insertsort_heap", referenced from:
_ks_combsort_heap in libbam.a(bam_sort.o)
_ks_introsort_heap in libbam.a(bam_sort.o)
"___ks_insertsort_sort", referenced from:
_ks_combsort_sort in libbam.a(bam_sort.o)
_ks_introsort_sort in libbam.a(bam_sort.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The latter error is not raised if gcc is used, but clang is the default compiler for OSX 10.8 (and latest FreeBSD too). One simple (and correct) solution is to make the inlined function static.
diff --git a/ksort.h b/ksort.h
index fa850ab..f8d8c4c 100644
--- a/ksort.h
+++ b/ksort.h
@@ -141,7 +141,7 @@ typedef struct {
tmp = *l; *l = l[i]; l[i] = tmp; ks_heapadjust_##name(0, i, l); \
} \
} \
- inline void __ks_insertsort_##name(type_t *s, type_t *t) \
+ static inline void __ks_insertsort_##name(type_t *s, type_t *t) \
{ \
type_t *i, *j, swap_tmp; \
for (i = s + 1; i < t; ++i) \
Great! It works!