2013-04-01 20 views
7

Witam Używam filtra boost i zlib do kompresowania i dekompresji danych. zgodnie z instrukcją strony doładowania mówi się: , jeśli plik .cpp zależy od biblioteki zewnętrznej, będziesz musiał zbudować ją ze źródła lub łącza do gotowego pliku binarnego.jak połączyć bibliotekę zlib

Użyłem portu mac do zainstalowania boost i zlib. I obejmują libarary doładowania jak -I/opt/local/include

mój kod:

#include <fstream> 
#include <iostream> 
#include <boost/iostreams/filtering_streambuf.hpp> 
#include <boost/iostreams/copy.hpp> 
#include <boost/iostreams/filter/zlib.hpp> 

int main() 
{ 
    using namespace std; 

    ifstream file("hello.z", ios_base::in | ios_base::binary); 
    filtering_streambuf<input> in; 
    in.push(zlib_decompressor()); 
    in.push(file); 
    boost::iostreams::copy(in, cout); 
} 

Zastanawiam się, jak połączyć wstępnie zbudowane zlib zewnętrznego libarary? daje mi to kompilujący się problem:

mpic++ -o local ods_v2.0.cpp -I/opt/local/include 
Undefined symbols for architecture x86_64: 
    "boost::iostreams::zlib_error::check(int)", referenced from: 
     long boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::write<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char const*, long) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::non_blocking_adapter<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::non_blocking_adapter<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
     long boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::read<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, char*, long) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
    "boost::iostreams::zlib::stream_end", referenced from: 
     long boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::write<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char const*, long) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::non_blocking_adapter<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::non_blocking_adapter<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
     long boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::read<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, char*, long) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
    "boost::iostreams::zlib::sync_flush", referenced from: 
     long boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::write<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char const*, long) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::non_blocking_adapter<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::non_blocking_adapter<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
     long boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::read<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, char*, long) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
    "boost::iostreams::zlib::default_strategy", referenced from: 
     boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::make_params(int) in ods_v2-DjDcji.o 
    "boost::iostreams::zlib::default_compression", referenced from: 
     boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::make_params(int) in ods_v2-DjDcji.o 
    "boost::iostreams::zlib::okay", referenced from: 
     long boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::write<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char const*, long) in ods_v2-DjDcji.o 
     void boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::close<boost::iostreams::non_blocking_adapter<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::non_blocking_adapter<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
     long boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::read<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char*, long) in ods_v2-DjDcji.o 
    "boost::iostreams::zlib::deflated", referenced from: 
     boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::make_params(int) in ods_v2-DjDcji.o 
    "boost::iostreams::detail::gzip_footer::reset()", referenced from: 
     long boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::write<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char const*, long) in ods_v2-DjDcji.o 
     long boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::read<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char*, long) in ods_v2-DjDcji.o 
     boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::basic_gzip_decompressor(int, int) in ods_v2-DjDcji.o 
    "boost::iostreams::detail::gzip_footer::process(char)", referenced from: 
     long boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::write<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char const*, long) in ods_v2-DjDcji.o 
     long boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::read<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char*, long) in ods_v2-DjDcji.o 
    "boost::iostreams::detail::gzip_header::reset()", referenced from: 
     long boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::write<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char const*, long) in ods_v2-DjDcji.o 
     long boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::read<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char*, long) in ods_v2-DjDcji.o 
     boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::basic_gzip_decompressor(int, int) in ods_v2-DjDcji.o 
    "boost::iostreams::detail::gzip_header::process(char)", referenced from: 
     long boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::write<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char const*, long) in ods_v2-DjDcji.o 
     long boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::read<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char*, long) in ods_v2-DjDcji.o 
    "boost::iostreams::detail::zlib_base::after(char const*&, char*&, bool)", referenced from: 
     long boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::write<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char const*, long) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::non_blocking_adapter<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::non_blocking_adapter<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
     long boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::read<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, char*, long) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
    "boost::iostreams::detail::zlib_base::reset(bool, bool)", referenced from: 
     boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close_impl() in ods_v2-DjDcji.o 
     boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::impl::impl<boost::iostreams::zlib_params>(int, boost::iostreams::zlib_params const&) in ods_v2-DjDcji.o 
     boost::detail::shared_count::shared_count<boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::impl>(boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::impl*) in ods_v2-DjDcji.o 
     boost::detail::sp_counted_impl_p<boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::impl>::dispose() in ods_v2-DjDcji.o 
    "boost::iostreams::detail::zlib_base::before(char const*&, char const*, char*&, char*)", referenced from: 
     long boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::write<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char const*, long) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::non_blocking_adapter<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::non_blocking_adapter<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
     long boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::read<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, char*, long) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
    "boost::iostreams::detail::zlib_base::do_init(boost::iostreams::zlib_params const&, bool, void* (*)(void*, unsigned int, unsigned int), void (*)(void*, void*), void*)", referenced from: 
     boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::impl::impl<boost::iostreams::zlib_params>(int, boost::iostreams::zlib_params const&) in ods_v2-DjDcji.o 
    "boost::iostreams::detail::zlib_base::xinflate(int)", referenced from: 
     long boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::write<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, char const*, long) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >(boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::non_blocking_adapter<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::non_blocking_adapter<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
     long boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::read<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, char*, long) in ods_v2-DjDcji.o 
     void boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::close<boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > >(boost::iostreams::basic_gzip_decompressor<std::allocator<char> >::peekable_source<boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >&, std::_Ios_Openmode) in ods_v2-DjDcji.o 
    "boost::iostreams::detail::zlib_base::zlib_base()", referenced from: 
     boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::impl::impl<boost::iostreams::zlib_params>(int, boost::iostreams::zlib_params const&) in ods_v2-DjDcji.o 
    "boost::iostreams::detail::zlib_base::~zlib_base()", referenced from: 
     boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::impl::impl<boost::iostreams::zlib_params>(int, boost::iostreams::zlib_params const&) in ods_v2-DjDcji.o 
     boost::detail::shared_count::shared_count<boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::impl>(boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::impl*) in ods_v2-DjDcji.o 
     boost::detail::sp_counted_impl_p<boost::iostreams::symmetric_filter<boost::iostreams::detail::zlib_decompressor_impl<std::allocator<char> >, std::allocator<char> >::impl>::dispose() in ods_v2-DjDcji.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 
make: *** [local] Error 1 

oraz jak zbudować i połączyć bibliotekę boost i zlib w klastrze unix? dzięki.

+0

Powinieneś być w stanie podać -lz na linii poleceń gcc –

+0

@weeo 'Ctrl + k' na wynik wcięcia/wyjście linii poleceń. –

+0

@JeffPaquette nadal jest ten sam błąd ... Używam mpi .. – weeo

Odpowiedz

8

Nie masz problemu z kompilatorem; masz problem z linkowaniem.

Dodaj -lboost_iostreams do linii poleceń. Aby podać ścieżkę, możesz potrzebować -L/opt/lib. To powinno dać ci inny błąd łącznika, szukając zlib. Następnie dodaj -lz.

Końcowa linia będzie wyglądać

mpic++ -o local ods_v2.0.cpp -I/opt/local/include -L/opt/lib -lboost_iostreams -lz 
+0

z -lboost_iostreams daje mi ld: biblioteka nie została znaleziona dla -lboost_iostreams z -lz tym samym błędem – weeo

+0

@weeo Spróbuj z '-L' po prostu dodał ... –

+0

co masz na myśli .... @ Alex Chamberlain – weeo

-4

doładowania ma doskonałą Getting Started przewodnika. Spójrz, to powinno pomóc Ci skompilować, zainstalować i połączyć z Boost.