Trouble Compiling C++ Code With Bamtools
2
1
Entering edit mode
7.9 years ago
user ▴ 870

I'm trying to link C++ code to the bamtools library. My directory structure is:

myproject/
  Makefile
  lib/
    bamtools-master/
  include/
  src/bam_example.cpp

The lib/bamtools-master/ file is the contents of https://github.com/pezmaster31/bamtools/archive/master.zip

My code is:

include "api/BamMultiReader.h"
#include "api/BamWriter.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
using namespace BamTools;
BamMultiReader reader;

int main(int argc, char* argv[]) {
  cerr << "Test";
}

The Makefile is:

bam_example:
    g++ -I ./lib/bamtools-master/include/ -L ./lib/bamtools-master/lib/ -o bam_example src/bam_example.cpp -lz -lbamtools

clean:
    rm bam_example

When I compile I get:

$ make
g++ -I ./lib/bamtools-master/include/ -L ./lib/bamtools-master/lib/ -o bam_example src/bam_example.cpp -lz -lbamtools
$ ./bam_example 
./bam_example: error while loading shared libraries: libbamtools.so.2.3.0: cannot open shared object file: No such file or directory

What went wrong here? What is the correct way to link to bamtools library?

What is wrong with this example?

samtools rna-seq • 6.2k views
ADD COMMENT
2
Entering edit mode
7.9 years ago
cts ★ 1.7k

I think your problem may be that the ./lib/bamtools-master/lib/ directory is not part of your LD_LIBRARY_PATH environmental variable. try typing export LD_LIBRARY_PATH=<PREFIX>/lib/bamtools-master/lib/:$LD_LIBRARY_PATH at the prompt then trying to run the command again.

ADD COMMENT
0
Entering edit mode

I think the error might actually be that I passed bamtools-master/lib and not bamtools-master/src to the -L option of g++?

ADD REPLY
1
Entering edit mode

The -L option takes a path to where ever the .so file is found (the one called libbamtools.so.2.3.0), so if it is in bamtools-master-src then you are correct.

ADD REPLY
0
Entering edit mode
6.1 years ago
moja.100t • 0

I've got in a same situation when I use MaLTA, that performs bamtools internally.I saw http://www.vcru.wisc.edu/simonlab/bioinformatics/programs/install/bamtools.html, but its section 9 is incollect.

Pasadena is right(adding /lib/). Thank you.

ADD COMMENT

Login before adding your answer.

Traffic: 1878 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6