Compile error when using bamtools api

268 views
Skip to first unread message

chen sun

unread,
Nov 11, 2014, 11:11:41 PM11/11/14
to bamtoo...@googlegroups.com
Hi all,
    Recent I am trying to use bamtools api directly in my code. 
    Firstly I write a toy example according to the tutorial, as follows:
#include <iostream>
#include <vector>
using namespace std;
#include "api/BamMultiReader.h"
#include "api/BamWriter.h"


using namespace BamTools;
int main(){
    // at some point, start our merge operation
    vector<string> inputFilenames;
    inputFilenames.push_back("~/");
    string outputFilename;
    // provide some input & output filenames
    // attempt to open our BamMultiReader
    BamMultiReader reader;
    if (!reader.Open(inputFilenames)) {
        cerr << "Could not open input BAM files." << endl;
        return 0;
    }
    // retrieve 'metadata' from BAM files, these are required by BamWriter
    const SamHeader header = reader.GetHeader();
    const RefVector references = reader.GetReferenceData();
    // attempt to open our BamWriter
    BamWriter writer;
    if (!writer.Open(outputFilename, header, references)) {
        cerr << "Could not open output BAM file" << endl;
        return 0;
    }
    // iterate through all alignments, only keeping ones with high map quality
    BamAlignment al;
    while (reader.GetNextAlignmentCore(al)) {
        if (al.MapQuality >= 90)
            writer.SaveAlignment(al);
    }
    // close the reader & writer
    reader.Close();
    writer.Close();
    // merge is now complete, continue whatever we were doing
    return 0;
}

Then I use the compile command that suggest by tutorial:
 g++ -I ~/bamtools/include -L ~/bamtools/lib -lbamtools -o bam_transform.o bam_transform.cpp

I got error as follows:
g++ -I /gpfs/home/c/src/bamtools/include -L /gpfs/home/c/src/bamtools/lib -lbamtools -o bam_transform.o bam_transform.cpp
/tmp/ccCX41dn.o: In function `main':
bam_transform.cpp:(.text+0xb3): undefined reference to `BamTools::BamMultiReader::BamMultiReader()'
bam_transform.cpp:(.text+0xc6): undefined reference to `BamTools::BamMultiReader::Open(std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)'
bam_transform.cpp:(.text+0x109): undefined reference to `BamTools::BamMultiReader::GetHeader() const'
bam_transform.cpp:(.text+0x11c): undefined reference to `BamTools::BamMultiReader::GetReferenceData() const'
bam_transform.cpp:(.text+0x12b): undefined reference to `BamTools::BamWriter::BamWriter()'
bam_transform.cpp:(.text+0x14c): undefined reference to `BamTools::BamWriter::Open(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, BamTools::SamHeader const&, std::vector<BamTools::RefData, std::allocator<BamTools::RefData> > const&)'
bam_transform.cpp:(.text+0x188): undefined reference to `BamTools::BamAlignment::BamAlignment()'
bam_transform.cpp:(.text+0x1b0): undefined reference to `BamTools::BamWriter::SaveAlignment(BamTools::BamAlignment const&)'
bam_transform.cpp:(.text+0x1c6): undefined reference to `BamTools::BamMultiReader::GetNextAlignmentCore(BamTools::BamAlignment&)'
bam_transform.cpp:(.text+0x1d6): undefined reference to `BamTools::BamMultiReader::Close()'
bam_transform.cpp:(.text+0x1e5): undefined reference to `BamTools::BamWriter::Close()'
bam_transform.cpp:(.text+0x1f9): undefined reference to `BamTools::BamAlignment::~BamAlignment()'
bam_transform.cpp:(.text+0x20f): undefined reference to `BamTools::BamAlignment::~BamAlignment()'
bam_transform.cpp:(.text+0x22b): undefined reference to `BamTools::BamWriter::~BamWriter()'
bam_transform.cpp:(.text+0x242): undefined reference to `BamTools::BamWriter::~BamWriter()'
bam_transform.cpp:(.text+0x27f): undefined reference to `BamTools::SamHeader::~SamHeader()'
bam_transform.cpp:(.text+0x296): undefined reference to `BamTools::SamHeader::~SamHeader()'
bam_transform.cpp:(.text+0x2a9): undefined reference to `BamTools::BamMultiReader::~BamMultiReader()'
bam_transform.cpp:(.text+0x2bd): undefined reference to `BamTools::BamMultiReader::~BamMultiReader()'
 
Is it because I do it in the wrong way, could someone point out how should I use the api more specifically.

Best,
Chen

Derek Barnett

unread,
Nov 11, 2014, 11:35:26 PM11/11/14
to bamtoo...@googlegroups.com
Hi Chen,
The error message indicates that g++ isn't finding the bamtools library. Make sure the library exists at the path you're pointing to.

Shoot me an email me directly ( derekw...@gmail.com ) and I can help you out further, instead of spamming the user list while we sort it out.

  - Derek



--
You received this message because you are subscribed to the Google Groups "bamtools-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bamtools-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages