I am trying to compile (on Linux, using G++) a simple main.cpp program using samtools C API (https://github.com/samtools/samtools) that I have downloaded in the folder of my main.cpp file. I would like to have a very simple makefile compiling the main.cpp (and eventually compiling samtools code). However, as I have very few knowledge about makefiles, I am probably doing something wrong.
Here is my makefile:
SAMTOOLS=./samtools/
HTSLIB=${SAMTOOLS}htslib-1.9/
all: samtools htslib BAMCoverage
samtools:
${MAKE} -C ${SAMTOOLS}
htslib:
${MAKE} -C ${HTSLIB}
BAMCoverage: main.cpp
g++ -I./ -I${SAMTOOLS} -I${HTSLIB} -g -O2 -Wall ./main.cpp -o ./BAMCoverage -lz -L${SAMTOOLS} -L${HTSLIB} -lbam -lhts
And here is my cpp main:
#include "samtools/sam.h"
#include <string>
#include <iostream>
using namespace std;
int main (int argc, char *argv[]) {
string bam_file_path ("myfile.bam");
bamFile bam_file = bam_open (bam_file_path.c_str (), "rb");
if (bam_file == 0) {
cerr << "Failed to open BAM file " << bam_file_path << endl;
return 1;
}
bam_close (bam_file);
return 0;
}
It compiles with no warning when I run "make", but at runtime, it tells me: "error while loading shared libraries: libhts.so.2 cannot open shared object file"
Any help is more than welcome! Thanks in advance.