htslib: undefined reference Error
1
0
Entering edit mode
18 months ago
enho ▴ 20

Hi Everyone,

I've been stuck with this problem for over a day now and I searched everywhere, I couldn't find any solution for this problem.

I am trying to use htslib and I have a very simple code:

#include <stdio.h>
#include <stdlib.h>
#include "/data/miniconda3/include/htslib/vcf.h"
#include "/data/miniconda3/include/htslib/hts.h"

int main(int argc, char **argv) {
htsFile *fp = hts_open(argv[1],"r");

return 0;
}


When I run this code, I get this error:

main.c:(.text+0x23): undefined reference to hts_open' collect2:
error: ld returned 1 exit status


I tried it on two different system both have RHEL as their os and gcc's updated.

Does anyone know what can be the problem and how can I solve it?

Thanks

htslib vcf c c++ samtools • 756 views
1
Entering edit mode

Can you please add the command you're using to compile? You may need to link to a library or a directory containing said library object.

0
Entering edit mode

Adding -lhts solved the problem, thanks :)

0
Entering edit mode

1
Entering edit mode
18 months ago

-lhts` is missing on your command for compiling.