jts / sga

de novo sequence assembler using string graphs
http://genome.cshlp.org/content/22/3/549
237 stars 82 forks source link

0.10.14 compilation error #122

Closed wookietreiber closed 7 years ago

wookietreiber commented 8 years ago
g++ -DHAVE_CONFIG_H -I. -I..  -I../Bigraph -I../Thirdparty -D_FORTIFY_SOURCE=2 -fopenmp  -I/usr/include/bamtools -Wall -Wextra  -Wno-unknown-pragmas -O3 -MT libutil_a-ClusterReader.o -MD -MP -MF .deps/libutil_a-ClusterReader.Tpo -c -o libutil_a-ClusterReader.o `test -f 'ClusterReader.cpp' || echo './'`ClusterReader.cpp
ClusterReader.cpp: In member function ‘bool ClusterReader::readCluster(ClusterRecord&)’:
ClusterReader.cpp:70:41: error: cannot convert ‘std::basic_istream<char>’ to ‘bool’ in initialization
     bool good = getline(*m_pReader, line);
                                         ^

System Info:

Arch Linux

Kernel: 4.6.4-1-ARCH Compiler: gcc (GCC) 6.1.1 20160707

boost 1.60.0 jemalloc 4.2.1 sparsehash 2.0.3 bamtools 2.4.0

mateidavid commented 7 years ago

I added #126 to address this.

wookietreiber commented 7 years ago

@mateidavid Thanks for providing the patch.

Now, unfortunately, it fails during linking, because it cannot find the bamtools library function that use C++11 features:

g++ -Wall -Wextra  -Wno-unknown-pragmas -O3 -pthread -fopenmp   -Wl,-O1,--sort-common,--as-needed,-z,relro -o sga sga-sga.o sga-index.o sga-overlap.o sga-assemble.o sga-correct.o sga-oview.o sga-preprocess.o sga-rmdup.o sga-merge.o sga-subgraph.o sga-scaffold.o sga-scaffold2fasta.o sga-connect.o sga-walk.o sga-filter.o sga-kmer-count.o sga-stats.o sga-fm-merge.o sga-gmap.o sga-filterBAM.o sga-cluster.o sga-gen-ssa.o sga-bwt2fa.o sga-graph-diff.o sga-graph-concordance.o sga-gapfill.o sga-preqc.o sga-overlap-long.o sga-variant-detectability.o sga-rewrite-evidence-bam.o sga-somatic-variant-filters.o sga-haplotype-filter.o sga-OverlapCommon.o ../Scaffold/libscaffold.a ../GraphDiff/libgraphdiff.a ../StringGraph/libstringgraph.a ../Concurrency/libconcurrency.a ../Algorithm/libalgorithm.a ../SuffixTools/libsuffixtools.a ../Bigraph/libbigraph.a ../Util/libutil.a ../SQG/libsqg.a ../Thirdparty/libthirdparty.a -L/usr/lib -ljemalloc -lz  -lbamtools
sga-somatic-variant-filters.o: In function `getVariantCoverage(BamTools::BamReader*, VCFRecord const&, ReadTable const*)':
somatic-variant-filters.cpp:(.text+0x3bc5): undefined reference to `BamTools::BamReader::GetReferenceID(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
sga-somatic-variant-filters.o: In function `somaticVariantFiltersMain(int, char**)':
somatic-variant-filters.cpp:(.text+0x47df): undefined reference to `BamTools::BamReader::Open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
somatic-variant-filters.cpp:(.text+0x4831): undefined reference to `BamTools::BamReader::Open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
sga-connect.o: In function `connectMain(int, char**)':
connect.cpp:(.text+0x1747): undefined reference to `BamTools::BamReader::Open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
sga-filterBAM.o: In function `getErrorRate(BamTools::BamAlignment&)':
filterBAM.cpp:(.text+0x870): undefined reference to `BamTools::BamAlignment::FindTag(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char*&, unsigned int const&, unsigned int&) const'
filterBAM.cpp:(.text+0xa0b): undefined reference to `BamTools::BamAlignment::SetErrorString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
filterBAM.cpp:(.text+0xcc3): undefined reference to `BamTools::BamAlignment::SetErrorString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
sga-filterBAM.o: In function `filterBAMMain(int, char**)':
filterBAM.cpp:(.text+0x1ba6): undefined reference to `BamTools::BamReader::Open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
filterBAM.cpp:(.text+0x1bd6): undefined reference to `BamTools::BamReader::GetHeaderText[abi:cxx11]() const'
filterBAM.cpp:(.text+0x1be9): undefined reference to `BamTools::BamWriter::Open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<BamTools::RefData, std::allocator<BamTools::RefData> > const&)'
sga-rewrite-evidence-bam.o: In function `rewriteEvidenceBAMMain(int, char**)':
rewrite-evidence-bam.cpp:(.text+0x6d9): undefined reference to `BamTools::BamReader::Open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
rewrite-evidence-bam.cpp:(.text+0x11fc): undefined reference to `BamTools::BamReader::GetHeaderText[abi:cxx11]() const'
rewrite-evidence-bam.cpp:(.text+0x1214): undefined reference to `BamTools::BamWriter::Open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<BamTools::RefData, std::allocator<BamTools::RefData> > const&)'
../GraphDiff/libgraphdiff.a(libgraphdiff_a-GraphCompare.o): In function `GraphCompareAggregateResults::GraphCompareAggregateResults(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, ReadTable const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
GraphCompare.cpp:(.text+0x25e8): undefined reference to `BamTools::SamHeader::SamHeader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
GraphCompare.cpp:(.text+0x2f2c): undefined reference to `BamTools::BamWriter::Open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, BamTools::SamHeader const&, std::vector<BamTools::RefData, std::allocator<BamTools::RefData> > const&)'
collect2: error: ld returned 1 exit status

All of these undefined references use something like std::__cxx11::..., which, I guess, can now not be found because of the C++98 standard we are currently using.

In the end, I would rather prefer a solution that does not drop the C++ standard back to the stone ages.

mateidavid commented 7 years ago

In short- rebuild BamTools master, not 2.4.0, then rebuild SGA.

Long version- IMO, the problem is that if you don't ask for a specific standard, you leave yourself open to such issues in the future. These errors happen with GCC6 because they updated the language standard from gnu++98 all the way to gnu++14. I don't know when gnu++17 will become default, but when it does, expect more such problems. Furthermore, SGA is actually written in pre-c++11 dialect, which is evident since it compiles just fine with gnu++98. There is nothing "stone agey" about requesting a specific dialect, it's just a way to protect from future changes, such as this business with std::istream to bool conversion.

Likewise, BamTools 2.4.0 (latest tag today) has errors with GCC6, but it compiles just fine with gnu++98. I created a PR setting the language that was already pulled into BamTools: https://github.com/pezmaster31/bamtools/pull/116 . So the next tagged release of BamTools with be compiled with gnu++98. The change is available in master, which is why I'm using git clone in the Dockerfile.testing as opposed to wget on a specific release.

Lastly, I tried to recreate the error as follows but I can't:

# a.hpp
#include <string>
void f(const std::string& s);

# a.cpp
#include "a.hpp"
void f(const std::string&) {}

# b.cpp
#include "a.hpp"
int main()
{
    std::string s;
    f(s);
}

# compile a.cpp to a.so with c++11
g++ -std=gnu++11 -shared -fPIC -o a.so a.cpp

# compile b.cpp with gnu++98
g++ -std=gnu++98 -c b.cpp

# link with g++98
g++ -std=gnu++98 -o b b.o a.so -Wl,--rpath=$PWD

I don't see those errors.

wookietreiber commented 7 years ago

I managed to get it to compile by recompiling BamTools 2.4.0 with the explicit C++ standard you mentioned. This way, we don't need to depend on current master branches but can work with the officially released versions, which in my case is what I want because I am maintaining software packages.

With this solution I am closing this issue. Thanks for your help @mateidavid.

Note to distribution package managers who might also experience these issues: I updated the Arch Linux packages for the latest officially released versions to date to incorporate these changes. If you want to copy these changes feel free to look at the builds and patches in the Arch Linux User Repository (AUR):