walaj / SeqLib

C++ htslib/bwa-mem/fermi interface for interrogating sequence data
http://bioinformatics.oxfordjournals.org/content/early/2016/12/21/bioinformatics.btw741.full.pdf+html
Other
132 stars 36 forks source link

undefined reference to xx error for a test #20

Closed taojinsheng closed 5 years ago

taojinsheng commented 7 years ago

Hi Jeremiah,

Following your intructions,I have successfully installed the library. However,when I tried to test it,I got following error although I specified the static library path: g++ -L/home/jinsheng_tao/software/SeqLib/bin/ test.cpp /tmp/ccGnVDiX.o: In function main': test.cpp:(.text+0xc8): undefined reference toSeqLib::BamReader::BamReader()' test.cpp:(.text+0x10b): undefined reference to SeqLib::BamReader::Open(std::string const&)' test.cpp:(.text+0x148): undefined reference toSeqLib::BamReader::Header() const' test.cpp:(.text+0x15e): undefined reference to SeqLib::BamWriter::SetHeader(SeqLib::BamHeader const&)' test.cpp:(.text+0x1ad): undefined reference toSeqLib::BamWriter::Open(std::string const&)' test.cpp:(.text+0x1d4): undefined reference to SeqLib::BamWriter::WriteHeader() const' test.cpp:(.text+0x20c): undefined reference toSeqLib::BamWriter::WriteRecord(SeqLib::BamRecord const&)' test.cpp:(.text+0x222): undefined reference to SeqLib::BamReader::GetNextRecord(SeqLib::BamRecord&)' test.cpp:(.text+0x235): undefined reference toSeqLib::BamWriter::Close()' test.cpp:(.text+0x244): undefined reference to `SeqLib::BamReader::Close()' collect2: error: ld returned 1 exit status

Below is my source code:

include <SeqLib/BamReader.h>

include <SeqLib/BamWriter.h>// #include "SeqLib/BWAWrapper.h"

include <SeqLib/BamRecord.h>

using namespace SeqLib;

int main(int argc,char* argv[]) { // open the reader BAM/SAM/CRAM SeqLib::BamReader r; r.Open(argv[1]);

// open a new interface to BWA-MEM
// BWAWrapper bwa;
// bwa.LoadIndex("hg19.fasta");

// open the output BAM
SeqLib::BamWriter w; // or writer(SeqLib::SAM) or writer(SeqLib::CRAM)
w.SetHeader(r.Header());
w.Open(argv[2]);
w.WriteHeader();

SeqLib::BamRecord rec;
bool hardclip = false;
float secondary_cutoff = 0.90; // secondary alignments must have score >= 0.9*top_score
int secondary_cap = 10; // max number of secondary alignments to return
while (r.GetNextRecord(rec)) {
    /*
    BamRecordVector results; // alignment results (can have multiple alignments)
    bwa.AlignSequence(r.Sequence(), r.Qname(), results, hardclip, secondary_cutoff, secondary_cap);

    for (auto& i : results)
        writer.WriteRecord(i);
    */
    w.WriteRecord(rec);
}
w.Close();
r.Close();
return 0;

} It would be greatly appreciated if you could help me with this problem.Many thanks.

Best regards, Jinsheng

walaj commented 7 years ago

Hi Jinsheng, When you link, can you give the full path to all the static libraries? You are giving g++ the path where to find libraries, but don't actually specify any. e.g.

SEQ=/home/jinsheng_tao/software/SeqLib
g++ $SEQ/bin/libseqlib.a $SEQ/bin/libbwa.a $SEQ/bin/libfml.a $SEQ/bin/libhts.a test.cpp
taojinsheng commented 7 years ago

Hi Jeremiah,

Thank you for your reply.I did what you suggested,but the sam error still coccurs: [15:27 jinsheng_tao@anchordx ~/code/cpp/readbam]$SEQ=/home/jinsheng_tao/software/SeqLib [15:29 jinsheng_tao@anchordx ~/code/cpp/readbam]$g++ $SEQ/bin/libseqlib.a $SEQ/bin/libbwa.a $SEQ/bin/libfml.a $SEQ/bin/libhts.a test.cpp /tmp/ccnSkNAq.o: In function main': test.cpp:(.text+0xc8): undefined reference toSeqLib::BamReader::BamReader()' test.cpp:(.text+0x10b): undefined reference to SeqLib::BamReader::Open(std::string const&)' test.cpp:(.text+0x148): undefined reference toSeqLib::BamReader::Header() const' test.cpp:(.text+0x15e): undefined reference to SeqLib::BamWriter::SetHeader(SeqLib::BamHeader const&)' test.cpp:(.text+0x1ad): undefined reference toSeqLib::BamWriter::Open(std::string const&)' test.cpp:(.text+0x1d4): undefined reference to SeqLib::BamWriter::WriteHeader() const' test.cpp:(.text+0x20c): undefined reference toSeqLib::BamWriter::WriteRecord(SeqLib::BamRecord const&)' test.cpp:(.text+0x222): undefined reference to SeqLib::BamReader::GetNextRecord(SeqLib::BamRecord&)' test.cpp:(.text+0x235): undefined reference toSeqLib::BamWriter::Close()' test.cpp:(.text+0x244): undefined reference to `SeqLib::BamReader::Close()' collect2: error: ld returned 1 exit status

alifare commented 6 years ago

/tmp/cc6Oayf5.o: In function main': test.cpp:(.text+0x77): undefined reference toSeqLib::RefGenome::LoadIndex(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)' /tmp/cc6Oayf5.o: In function SeqLib::RefGenome::~RefGenome()': test.cpp:(.text._ZN6SeqLib9RefGenomeD2Ev[_ZN6SeqLib9RefGenomeD5Ev]+0x23): undefined reference tofai_destroy' collect2: error: ld returned 1 exit status

alifare commented 6 years ago

Hi Jeremiah,

Is there any easier way to use SeqLib in my own program, just like Boost C++ Libraries or something like that?

What I need is just use BWA-MEM in computer memory, so it's wasting time to deal with these annoying compiling issues. Anyway, most users of SeqLib are not compute major.

RainyEricYe commented 6 years ago

Hi, Abel Chang,SebLib is already easy to use now although depending on version of g++ and stdlib.Boost is written by computer engineers, not bioinformatical scientists 😄RuiFrom my iPhone------------------ Original ------------------From: Abel Chang notifications@github.comDate: Sun,Dec 17,2017 17:55To: walaj/SeqLib SeqLib@noreply.github.comCc: Subscribed subscribed@noreply.github.comSubject: Re: [walaj/SeqLib] undefined reference to xx error for a test (#20)Hi Jeremiah, Is there any easier way to use SeqLib in my own program, just like Boost C++ Libraries or something like that? What I need is just use BWA-MEM in computer memory, so it's wasting time to deal with these annoying compiling issues. Anyway, most users of SeqLib are not compute major.

—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or mute the thread.

{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/walaj/SeqLib","title":"walaj/SeqLib","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/walaj/SeqLib"}},"updates":{"snippets":[{"icon":"PERSON","message":"@alifare in #20: Hi Jeremiah,\r\n\r\nIs there any easier way to use SeqLib in my own program, just like Boost C++ Libraries or something like that?\r\n\r\nWhat I need is just use BWA-MEM in computer memory, so it's wasting time to deal with these annoying compiling issues. Anyway, most users of SeqLib are not compute major."}],"action":{"name":"View Issue","url":"https://github.com/walaj/SeqLib/issues/20#issuecomment-352244071"}}}

walaj commented 6 years ago

For linking issues, I would refer to the source code for https://github.com/walaj/svaba, https://github.com/walaj/VariantBam and https://github.com/walaj/bxtools, all of which show examples of linking with SeqLib. It would be nice if these were header-only libraries like much of Boost, but alas they are not!

NickRoz1 commented 5 years ago

Hello! I have same issue and I don't understand what I'm doing wrong.

I have built SeqLib library and add new environment variables:

C_INCLUDE_PATH=/usr/local/lib/seqlib/SeqLib:/usr/local/lib/seqlib/SeqLib/htslib
CPATH=/usr/local/lib/seqlib/SeqLib:/usr/local/lib/seqlib/SeqLib/htslib
LDFLAGS=/usr/local/lib/seqlib/SeqLib/lib/libseqlib.a /usr/local/lib/seqlib/SeqLib/lib/libbwa.a /usr/local    /lib/seqlib/SeqLib/lib/libfml.a /usr/local/lib/seqlib/SeqLib/lib/libhts.a

Here is my sample code:

include "SeqLib/BamReader.h"

#include "SeqLib/RefGenome.h"
using namespace SeqLib;

int main(){
    RefGenome ref;
    BamReader k = BamReader();
    k.IsOpen();
    return 0;
}

Error:

g++ parq.cpp
/tmp/ccT7AQQy.o: In function `main':
parq.cpp:(.text+0xe5): undefined reference to `SeqLib::BamReader::BamReader()'
/tmp/ccT7AQQy.o: In function `SeqLib::RefGenome::~RefGenome()':
parq.cpp:(.text._ZN6SeqLib9RefGenomeD2Ev[_ZN6SeqLib9RefGenomeD5Ev]+0x23): undefined reference to `fai_destroy'
collect2: error: ld returned 1 exit status

I've also tried specifying full library paths, same error.

Best Regards, Nick

walaj commented 5 years ago

Hi Nick, Can you show me the output of the compiler at the linking step? I suspect your env vars are not being passed to your compiler.