2013-04-01 2 views
7

Привет, я использую фильтр boost и zlib для сжатия и распаковки данных. по команде boost page, говорится: , если файл .cpp зависит от внешней библиотеки, вам придется построить его из источника или ссылки в предварительно построенный двоичный файл.Как связать библиотеку zlib

Я использовал порт mac для установки boost и zlib. Я включаю повысить libarary как -I/Opt/местные/включить

мой код:

#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); 
} 

Интересно, как связать преднастроенным ZLIB внешний libarary? она дает мне эту проблему компилирования:

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 

и как строить и ссылку подталкивание и библиотеку ZLIB на UNIX кластера? Благодарю.

+0

Вы должны иметь возможность указать -lz в командной строке gcc –

+0

@weeo 'Ctrl + k' для вывода отступа/вывода командной строки. –

+0

@JeffPaquette это по-прежнему та же ошибка ... Я использую mpi .. – weeo

ответ

8

У вас нет проблемы с компилятором; у вас есть проблема с привязкой.

Добавить -lboost_iostreams в командную строку. Для указания пути вам может понадобиться -L/opt/lib. Это должно дать вам еще одну ошибку компоновщика, ища zlib. Затем добавьте -lz.

Последняя строка будет выглядеть

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

с -lboost_iostreams это дает мне ld: библиотека не найдена для -lboost_iostreams с -lz та же ошибка – weeo

+0

@weeo Попробуйте с '-L' просто добавлено ... –

+0

что вы имеете в виду .... @ Alex Chamberlain – weeo

-4

подталкивания имеет отличную Getting Started руководство. Взгляните, это должно помочь вам скомпилировать, установить и связать с Boost.

Смежные вопросы