【问题标题】:boost iostreams compilation errorboost iostreams 编译错误
【发布时间】:2016-11-20 02:00:24
【问题描述】:

这是我的编译行:

g++ -std=c++11 -Wall -Wextra -g -lboost_iostreams cppfile.cpp -o bin

但我有以下错误:

/tmp/cclste3G.o: In function `trie::write_on_disk(char*)':
undefined reference to `boost::iostreams::zlib::default_strategy'
undefined reference to `boost::iostreams::zlib::deflated'
undefined reference to `boost::iostreams::zlib::default_compression'
/tmp/cclste3G.o: In function `boost::iostreams::basic_gzip_compressor<std::allocator<char> >::basic_gzip_compressor(boost::iostreams::gzip_params const&, int)':
/usr/include/boost/iostreams/filter/gzip.hpp:671: undefined reference to `boost::iostreams::zlib::best_compression'
/usr/include/boost/iostreams/filter/gzip.hpp:671: undefined reference to `boost::iostreams::zlib::best_speed'
/tmp/cclste3G.o: In function `boost::iostreams::detail::zlib_compressor_impl<std::allocator<char> >::zlib_compressor_impl(boost::iostreams::zlib_params const&)':
/usr/include/boost/iostreams/filter/zlib.hpp:338: undefined reference to `boost::iostreams::detail::zlib_base::zlib_base()'
/usr/include/boost/iostreams/filter/zlib.hpp:338: undefined reference to `boost::iostreams::detail::zlib_base::~zlib_base()'
/tmp/cclste3G.o: In function `boost::iostreams::detail::zlib_compressor_impl<std::allocator<char> >::~zlib_compressor_impl()':
/usr/include/boost/iostreams/filter/zlib.hpp:343: undefined reference to `boost::iostreams::detail::zlib_base::reset(bool, bool)'
/usr/include/boost/iostreams/filter/zlib.hpp:343: undefined reference to `boost::iostreams::detail::zlib_base::~zlib_base()'
/tmp/cclste3G.o: In function `void boost::iostreams::detail::zlib_base::init<std::allocator<char> >(boost::iostreams::zlib_params const&, bool, boost::iostreams::detail::zlib_allocator<std::allocator<char>, boost::iostreams::detail::zlib_allocator_traits<std::allocator<char> >::type>&)':
/usr/include/boost/iostreams/filter/zlib.hpp:185: undefined reference to `boost::iostreams::detail::zlib_base::do_init(boost::iostreams::zlib_params const&, bool, void* (*)(void*, unsigned int, unsigned int), void (*)(void*, void*), void*)'
/tmp/cclste3G.o: In function `boost::iostreams::detail::zlib_compressor_impl<std::allocator<char> >::filter(char const*&, char const*, char*&, char*, bool)':
/usr/include/boost/iostreams/filter/zlib.hpp:350: undefined reference to `boost::iostreams::detail::zlib_base::before(char const*&, char const*, char*&, char*)'
/usr/include/boost/iostreams/filter/zlib.hpp:351: undefined reference to `boost::iostreams::zlib::finish'
/usr/include/boost/iostreams/filter/zlib.hpp:351: undefined reference to `boost::iostreams::zlib::no_flush'
/usr/include/boost/iostreams/filter/zlib.hpp:351: undefined reference to `boost::iostreams::detail::zlib_base::xdeflate(int)'
/usr/include/boost/iostreams/filter/zlib.hpp:352: undefined reference to `boost::iostreams::detail::zlib_base::after(char const*&, char*&, bool)'
/usr/include/boost/iostreams/filter/zlib.hpp:353: undefined reference to `boost::iostreams::zlib_error::check(int)'
/usr/include/boost/iostreams/filter/zlib.hpp:354: undefined reference to `boost::iostreams::zlib::stream_end'
/tmp/cclste3G.o: In function `boost::iostreams::detail::zlib_compressor_impl<std::allocator<char> >::close()':
/usr/include/boost/iostreams/filter/zlib.hpp:358: undefined reference to `boost::iostreams::detail::zlib_base::reset(bool, bool)'

我使用 -lboost_iostreams,所以我不明白为什么会出现此错误

问候

【问题讨论】:

  • -lboost_iostreams放在cppfile.cpp之后有用吗?
  • @SurvivalMachine 是的,它可以工作:D 谢谢!怎么可能^^"
  • @perecastor : 链接器标志的顺序很重要。

标签: c++ gcc boost compilation iostream


【解决方案1】:

您可以通过将链接器标志-lboost_iostreams 放在cppfile.cpp 之后来解决此问题。顺序很重要。

【讨论】:

    【解决方案2】:
    #Before all please install zlib library
    apt-get install zlib1g
    apt-get install zlib1g-dev
    
    #Try to add [ -lz ] option in command line
    g++ -std=c++11 -Wall -Wextra -g -lboost_iostreams -lz cppfile.cpp -o bin
    
    #If mentioned don't work, find exact position of libz.so and add -L option in command line 
    g++ -std=c++11 -Wall -Wextra -g -lboost_iostreams -lz cppfile.cpp -o bin -L/usr/share
    

    【讨论】:

      猜你喜欢
      • 2017-10-24
      • 2016-08-10
      • 2014-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多