I have downloaded and installed a library called htslib for specific bioinformatic use but not for the system (I'm using Ubuntu 18.04). Only parts of the library is needed for my exercise to parse data in a type called VCF format (basically tab-delimited file but contains many information in columns).
- My test code (vcf_parser01.c) is attached to make use the VCF API from the htslib, for which the vcf part seems to be what I need and the vcf.h/vcf.c files are also attached here. Maybe the whole htslib is needed, that's one of the parts I need to confirm.
- The htslib was compiled and installed locally without error through Makefile with the package, and the structure of the resulted folder is like:
.
├── aclocal.m4
├── bgzf.c
├── bgzf.o
├── bgzip.c
├── bgzip.o
├── config.h
......
|── cram
│ ├── cram_codecs.c
│ ├── cram_codecs.h
│ ├── cram_codecs.o
......
├── header.c
├── header.h
├── header.o
......
├── hts.c
├── htsfile.c
├── htsfile.o
├── hts_internal.h
├── htslib
│ ├── faidx.h
│ ├── hfile.h
│ ├── hts_defs.h
│ ├── hts_endian.h
│ ├── hts.h
......
├── kstring.c
├── kstring.o
├── vcf.c
├── vcf.o
......
3) To compile my test code, I used:
gcc -Wall -O3 -I ./htslib-1.10.2/htslib -o vcf_parser01 vcf.c vcf_parser01.c
4) There are many errors believed to the linker related such as:
vcf_parser01.c:(.text.startup+0x19): undefined reference to `hts_open'
vcf_parser01.c:(.text.startup+0x73): undefined reference to `hts_close'
/tmp/cc05JReL.o: In function `bcf_hdr_add_sample_len':
vcf.c:(.text+0x989): undefined reference to `hts_log'
/tmp/cc05JReL.o: In function `bcf_hdr_set_idx.isra.10':
vcf.c:(.text+0x116b): undefined reference to `hts_log'
vcf.c:(.text+0x11d5): undefined reference to `hts_resize_array_'
/tmp/cc05JReL.o: In function `bcf_subset_format.part.19':
vcf.c:(.text+0x18e5): undefined reference to `hts_realloc_or_die'
/tmp/cc05JReL.o: In function `bcf_hdr_format.constprop.30':
vcf.c:(.text+0x1e35): undefined reference to `ksprintf'
vcf.c:(.text+0x1e73): undefined reference to `ksprintf'
vcf.c:(.text+0x1ed3): undefined reference to `ksprintf'
There were totally 196 "undefined reference to" lines for 39 functions, which seems involving other libraries!
My question is:
How to debug this linker problem?
I think I understand the .o .so .a files, and the -I/-L options for gcc but not in full good catch.
A bigger picture in my mind is to learn how to make use of any non-standard C libraries from others, especially when documentation of the API is not very clear. I narrow down the topic in ANSI/GNU C in Linux platform only.
I may need a full course on this, but I know there are C experts in the forum. Really appreciate anybody could help me out.