как связать библиотеку zlib

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

Я использовал порт Mac для установки boost и zlib. Я включаю повышение библиотеки как
-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 внешнюю библиотеку? это дает мне эту проблему компиляции:

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

а как собрать и связать библиотеки boost и zlib на кластере unix? Благодарю.

7

Решение

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

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

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

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

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector