Question: Trouble Compiling C++ Code With Bamtools
1
gravatar for user
5.7 years ago by
user820
United States
user820 wrote:

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 • 5.1k views
ADD COMMENTlink modified 3.9 years ago by moja.100t0 • written 5.7 years ago by user820
1
gravatar for cts
5.7 years ago by
cts1.6k
Pasadena
cts1.6k wrote:

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 COMMENTlink written 5.7 years ago by cts1.6k

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 REPLYlink written 5.7 years ago by user820
1

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 REPLYlink written 5.7 years ago by cts1.6k
0
gravatar for moja.100t
3.9 years ago by
moja.100t0
moja.100t0 wrote:

I've got in a same situation when I use MaLTA( http://alan.cs.gsu.edu/NGS/?q=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 COMMENTlink modified 3.9 years ago • written 3.9 years ago by moja.100t0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 777 users visited in the last hour