This is a test version of Biostars. For the public version, visit https://www.biostars.org.
htslib: undefined reference Error

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

samtools htslib vcf cpp c

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.

Adding -lhts solved the problem, thanks :)

validate my answer please (green mark on the left )

1 answer

-lhts is missing on your command for compiling.

Log in to answer this question.