xmake-io / xmake-repo

📦 An official xmake package repository
https://xrepo.xmake.io
Apache License 2.0
669 stars 393 forks source link

Unable to compile boost library with iostream's compression #4866

Closed 01Pollux closed 1 month ago

01Pollux commented 1 month ago

Xmake Version

v2.9.4+HEAD.e85b001f1

Operating System Version and Architecture

Windows 11 23H2

Describe Bug

As the title says, i get attempt to index a nil value (local 'dep') error when attempting to install boost with iostreams+lzma.

Expected Behavior

The boost with iostreams+lzma library to be correctly installed.

Project Configuration

add_rules("mode.debug", "mode.release")
add_requires("boost", {system = false, configs = {
    iostreams = true,
    lzma = true,
}})
target("test")
    set_kind("binary")
    add_files("src/*.cpp")
    add_packages("boost")

Additional Information and Error Logs

boost.log

waruqi commented 1 month ago

try this patch https://github.com/xmake-io/xmake-repo/pull/4868

01Pollux commented 1 month ago

Sorry for late reply, it does compile however i get link time error when using library. (Example taken from boost-xmake's lzma test)

#include <boost/iostreams/filter/lzma.hpp>
#include <boost/iostreams/filtering_stream.hpp>
void main() {
    boost::iostreams::filtering_ostream out;
    out.push(boost::iostreams::lzma_compressor());
}

Produces the following:

1>EXEC : error : main.cpp.obj : error LNK2019: unresolved external symbol "public: static void __cdecl boost::iostreams::lzma_error::check(int)" (?check@lzma_error@iostreams@boost@@SAXH@Z) referenced in function "public: bool __cdecl boost::iostreams::detail::lzma_compressor_impl<class std::allocator<char> >::filter(char const * &,char const *,char * &,char *,bool)" (?filter@?$lzma_compressor_impl@V?$allocator@D@std@@@detail@iostreams@boost@@QEAA_NAEAPEBDPEBDAEAPEADPEAD_N@Z)
1>main.cpp.obj : error LNK2019: unresolved external symbol "protected: __cdecl boost::iostreams::detail::lzma_base::lzma_base(void)" (??0lzma_base@detail@iostreams@boost@@IEAA@XZ) referenced in function "public: __cdecl boost::iostreams::detail::lzma_compressor_impl<class std::allocator<char> >::lzma_compressor_impl<class std::allocator<char> >(struct boost::iostreams::lzma_params const &)" (??0?$lzma_compressor_impl@V?$allocator@D@std@@@detail@iostreams@boost@@QEAA@AEBUlzma_params@23@@Z)
1>main.cpp.obj : error LNK2019: unresolved external symbol "protected: __cdecl boost::iostreams::detail::lzma_base::~lzma_base(void)" (??1lzma_base@detail@iostreams@boost@@IEAA@XZ) referenced in function "int `public: __cdecl boost::iostreams::detail::lzma_compressor_impl<class std::allocator<char> >::lzma_compressor_impl<class std::allocator<char> >(struct iostreams::detail::lzma_params const &)'::`1'::dtor$0" (?dtor$0@?0???0?$lzma_compressor_impl@V?$allocator@D@std@@@detail@iostreams@boost@@QEAA@AEBUlzma_params@23@@Z@4HA)
1>main.cpp.obj : error LNK2019: unresolved external symbol "protected: void __cdecl boost::iostreams::detail::lzma_base::before(char const * &,char const *,char * &,char *)" (?before@lzma_base@detail@iostreams@boost@@IEAAXAEAPEBDPEBDAEAPEADPEAD@Z) referenced in function "public: bool __cdecl boost::iostreams::detail::lzma_compressor_impl<class std::allocator<char> >::filter(char const * &,char const *,char * &,char *,bool)" (?filter@?$lzma_compressor_impl@V?$allocator@D@std@@@detail@iostreams@boost@@QEAA_NAEAPEBDPEBDAEAPEADPEAD_N@Z)
1>main.cpp.obj : error LNK2019: unresolved external symbol "protected: void __cdecl boost::iostreams::detail::lzma_base::after(char const * &,char * &,bool)" (?after@lzma_base@detail@iostreams@boost@@IEAAXAEAPEBDAEAPEAD_N@Z) referenced in function "public: bool __cdecl boost::iostreams::detail::lzma_compressor_impl<class std::allocator<char> >::filter(char const * &,char const *,char * &,char *,bool)" (?filter@?$lzma_compressor_impl@V?$allocator@D@std@@@detail@iostreams@boost@@QEAA_NAEAPEBDPEBDAEAPEADPEAD_N@Z)
1>main.cpp.obj : error LNK2019: unresolved external symbol "protected: int __cdecl boost::iostreams::detail::lzma_base::deflate(int)" (?deflate@lzma_base@detail@iostreams@boost@@IEAAHH@Z) referenced in function "public: bool __cdecl boost::iostreams::detail::lzma_compressor_impl<class std::allocator<char> >::filter(char const * &,char const *,char * &,char *,bool)" (?filter@?$lzma_compressor_impl@V?$allocator@D@std@@@detail@iostreams@boost@@QEAA_NAEAPEBDPEBDAEAPEADPEAD_N@Z)
1>main.cpp.obj : error LNK2019: unresolved external symbol "protected: void __cdecl boost::iostreams::detail::lzma_base::reset(bool,bool)" (?reset@lzma_base@detail@iostreams@boost@@IEAAX_N0@Z) referenced in function "public: __cdecl boost::iostreams::detail::lzma_compressor_impl<class std::allocator<char> >::~lzma_compressor_impl<class std::allocator<char> >(void)" (??1?$lzma_compressor_impl@V?$allocator@D@std@@@detail@iostreams@boost@@QEAA@XZ)
1>main.cpp.obj : error LNK2019: unresolved external symbol "private: void __cdecl boost::iostreams::detail::lzma_base::do_init(struct boost::iostreams::lzma_params const &,bool,void * (__cdecl*)(void *,unsigned __int64,unsigned __int64),void (__cdecl*)(void *,void *),void *)" (?do_init@lzma_base@detail@iostreams@boost@@AEAAXAEBUlzma_params@34@_NP6APEAXPEAX_K3@ZP6AX22@Z2@Z) referenced in function "protected: void __cdecl boost::iostreams::detail::lzma_base::init<class std::allocator<char> >(struct boost::iostreams::lzma_params const &,bool,struct boost::iostreams::detail::lzma_allocator<class std::allocator<char>,class std::allocator<char> > &)" (??$init@V?$allocator@D@std@@@lzma_base@detail@iostreams@boost@@IEAAXAEBUlzma_params@23@_NAEAU?$lzma_allocator@V?$allocator@D@std@@V12@@123@@Z)
1>main.cpp.obj : error LNK2001: unresolved external symbol "unsigned int const boost::iostreams::lzma::default_compression" (?default_compression@lzma@iostreams@boost@@3IB)
1>main.cpp.obj : error LNK2001: unresolved external symbol "int const boost::iostreams::lzma::stream_end" (?stream_end@lzma@iostreams@boost@@3HB)
1>main.cpp.obj : error LNK2001: unresolved external symbol "int const boost::iostreams::lzma::finish" (?finish@lzma@iostreams@boost@@3HB)
1>main.cpp.obj : error LNK2001: unresolved external symbol "int const boost::iostreams::lzma::run" (?run@lzma@iostreams@boost@@3HB)
1>build\windows\x64\debug\test.exe : fatal error LNK1120: 12 unresolved externals
star-hengxing commented 1 month ago

Fixed https://github.com/xmake-io/xmake-repo/commit/aee03950d1a752988155b309b65d91f633623a45, try it again

01Pollux commented 1 month ago

Now its a different error, related to lzma

1>EXEC : error : libboost_iostreams-mt-s.lib(lzma.obj) : error LNK2019: unresolved external symbol lzma_code referenced in function "protected: int __cdecl boost::iostreams::detail::lzma_base::deflate(int)" (?deflate@lzma_base@detail@iostreams@boost@@IEAAHH@Z)
1>libboost_iostreams-mt-s.lib(lzma.obj) : error LNK2019: unresolved external symbol lzma_end referenced in function "protected: void __cdecl boost::iostreams::detail::lzma_base::reset(bool,bool)" (?reset@lzma_base@detail@iostreams@boost@@IEAAX_N0@Z)
1>libboost_iostreams-mt-s.lib(lzma.obj) : error LNK2019: unresolved external symbol lzma_stream_encoder_mt referenced in function "private: void __cdecl boost::iostreams::detail::lzma_base::init_stream(bool)" (?init_stream@lzma_base@detail@iostreams@boost@@AEAAX_N@Z)
1>libboost_iostreams-mt-s.lib(lzma.obj) : error LNK2019: unresolved external symbol lzma_stream_decoder referenced in function "private: void __cdecl boost::iostreams::detail::lzma_base::init_stream(bool)" (?init_stream@lzma_base@detail@iostreams@boost@@AEAAX_N@Z)
1>libboost_iostreams-mt-s.lib(lzma.obj) : error LNK2019: unresolved external symbol lzma_cputhreads referenced in function "private: void __cdecl boost::iostreams::detail::lzma_base::do_init(struct boost::iostreams::lzma_params const &,bool,void * (__cdecl*)(void *,unsigned __int64,unsigned __int64),void (__cdecl*)(void *,void *),void *)" (?do_init@lzma_base@detail@iostreams@boost@@AEAAXAEBUlzma_params@34@_NP6APEAXPEAX_K3@ZP6AX22@Z2@Z)
1>build\windows\x64\debug\test.exe : fatal error LNK1120: 5 unresolved externals
star-hengxing commented 1 month ago

It weird. This error is caused when boost not use LZMA_API_STATIC macro for compilation. But local test work for me.

https://github.com/xmake-io/xmake-repo/blob/aee03950d1a752988155b309b65d91f633623a45/packages/b/boost/xmake.lua#L317-L320

01Pollux commented 1 month ago

Huh, you're right, my bad, i was also adding package lzma and xz. There is also similar issue that outputs missing function definitions in boost::iostreams::detail::gzip_* and boost::iostreams::zlib*, perhaps i should create a new issue or append to this one?

the code:

#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/device/array.hpp>
#include <vector>
#include <iostream>

void main() {

    // Compressed code
    static constexpr char compressedCode[] = { 0x1F, 0x8B, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xFF, 0xF3, 0x48, 0xCD, 0xC9, 0xC9, 0xD7, 0x51, 0x8, 0xCF, 0x2F, 0xCA, 0x49, 0x51, 0x4, 0x0, 0xD0, 0xC3, 0x4A, 0xEC, 0xD, 0x0, 0x0, 0x0 };

    // Decompressed code
    std::vector<char> decompressedCode;

    namespace bio = boost::iostreams;

    bio::filtering_istream stream;
    stream.push(bio::gzip_decompressor());
    stream.push(bio::array_source(compressedCode, sizeof(compressedCode)));
    bio::copy(stream, std::back_inserter(decompressedCode));

    // Print decompressed code
    std::cout << std::string(decompressedCode.data(), decompressedCode.size()) << std::endl;
}

the error:

1>EXEC : error : main.cpp.obj : error LNK2019: unresolved external symbol "public: static void __cdecl boost::iostreams::zlib_error::check(int)" (?check@zlib_error@iostreams@boost@@SAXH@Z) referenced in function "public: bool __cdecl boost::iostreams::detail::zlib_decompressor_impl<class std::allocator<char> >::filter(char const * &,char const *,char * &,char *,bool)" (?filter@?$zlib_decompressor_impl@V?$allocator@D@std@@@detail@iostreams@boost@@QEAA_NAEAPEBDPEBDAEAPEADPEAD_N@Z)
1>main.cpp.obj : error LNK2019: unresolved external symbol "protected: __cdecl boost::iostreams::detail::zlib_base::zlib_base(void)" (??0zlib_base@detail@iostreams@boost@@IEAA@XZ) referenced in function "public: __cdecl boost::iostreams::detail::zlib_decompressor_impl<class std::allocator<char> >::zlib_decompressor_impl<class std::allocator<char> >(struct boost::iostreams::zlib_params const &)" (??0?$zlib_decompressor_impl@V?$allocator@D@std@@@detail@iostreams@boost@@QEAA@AEBUzlib_params@23@@Z)
1>main.cpp.obj : error LNK2019: unresolved external symbol "protected: __cdecl boost::iostreams::detail::zlib_base::~zlib_base(void)" (??1zlib_base@detail@iostreams@boost@@IEAA@XZ) referenced in function "int `public: __cdecl boost::iostreams::detail::zlib_decompressor_impl<class std::allocator<char> >::zlib_decompressor_impl<class std::allocator<char> >(struct iostreams::detail::zlib_params const &)'::`1'::dtor$0" (?dtor$0@?0???0?$zlib_decompressor_impl@V?$allocator@D@std@@@detail@iostreams@boost@@QEAA@AEBUzlib_params@23@@Z@4HA)
1>main.cpp.obj : error LNK2019: unresolved external symbol "protected: void __cdecl boost::iostreams::detail::zlib_base::before(char const * &,char const *,char * &,char *)" (?before@zlib_base@detail@iostreams@boost@@IEAAXAEAPEBDPEBDAEAPEADPEAD@Z) referenced in function "public: bool __cdecl boost::iostreams::detail::zlib_decompressor_impl<class std::allocator<char> >::filter(char const * &,char const *,char * &,char *,bool)" (?filter@?$zlib_decompressor_impl@V?$allocator@D@std@@@detail@iostreams@boost@@QEAA_NAEAPEBDPEBDAEAPEADPEAD_N@Z)
1>main.cpp.obj : error LNK2019: unresolved external symbol "protected: void __cdecl boost::iostreams::detail::zlib_base::after(char const * &,char * &,bool)" (?after@zlib_base@detail@iostreams@boost@@IEAAXAEAPEBDAEAPEAD_N@Z) referenced in function "public: bool __cdecl boost::iostreams::detail::zlib_decompressor_impl<class std::allocator<char> >::filter(char const * &,char const *,char * &,char *,bool)" (?filter@?$zlib_decompressor_impl@V?$allocator@D@std@@@detail@iostreams@boost@@QEAA_NAEAPEBDPEBDAEAPEADPEAD_N@Z)
1>main.cpp.obj : error LNK2019: unresolved external symbol "protected: int __cdecl boost::iostreams::detail::zlib_base::xinflate(int)" (?xinflate@zlib_base@detail@iostreams@boost@@IEAAHH@Z) referenced in function "public: bool __cdecl boost::iostreams::detail::zlib_decompressor_impl<class std::allocator<char> >::filter(char const * &,char const *,char * &,char *,bool)" (?filter@?$zlib_decompressor_impl@V?$allocator@D@std@@@detail@iostreams@boost@@QEAA_NAEAPEBDPEBDAEAPEADPEAD_N@Z)
1>main.cpp.obj : error LNK2019: unresolved external symbol "protected: void __cdecl boost::iostreams::detail::zlib_base::reset(bool,bool)" (?reset@zlib_base@detail@iostreams@boost@@IEAAX_N0@Z) referenced in function "public: __cdecl boost::iostreams::detail::zlib_decompressor_impl<class std::allocator<char> >::~zlib_decompressor_impl<class std::allocator<char> >(void)" (??1?$zlib_decompressor_impl@V?$allocator@D@std@@@detail@iostreams@boost@@QEAA@XZ)
1>main.cpp.obj : error LNK2019: unresolved external symbol "private: void __cdecl boost::iostreams::detail::zlib_base::do_init(struct boost::iostreams::zlib_params const &,bool,void * (__cdecl*)(void *,unsigned int,unsigned int),void (__cdecl*)(void *,void *),void *)" (?do_init@zlib_base@detail@iostreams@boost@@AEAAXAEBUzlib_params@34@_NP6APEAXPEAXII@ZP6AX22@Z2@Z) referenced in function "protected: void __cdecl boost::iostreams::detail::zlib_base::init<class std::allocator<char> >(struct boost::iostreams::zlib_params const &,bool,struct boost::iostreams::detail::zlib_allocator<class std::allocator<char>,class std::allocator<char> > &)" (??$init@V?$allocator@D@std@@@zlib_base@detail@iostreams@boost@@IEAAXAEBUzlib_params@23@_NAEAU?$zlib_allocator@V?$allocator@D@std@@V12@@123@@Z)
1>main.cpp.obj : error LNK2019: unresolved external symbol "public: void __cdecl boost::iostreams::detail::gzip_header::process(char)" (?process@gzip_header@detail@iostreams@boost@@QEAAXD@Z) referenced in function "public: __int64 __cdecl boost::iostreams::basic_gzip_decompressor<class std::allocator<char> >::read<class boost::iostreams::detail::linked_streambuf<char,struct std::char_traits<char> > >(class boost::iostreams::detail::linked_streambuf<char,struct std::char_traits<char> > &,char *,__int64)" (??$read@V?$linked_streambuf@DU?$char_traits@D@std@@@detail@iostreams@boost@@@?$basic_gzip_decompressor@V?$allocator@D@std@@@iostreams@boost@@QEAA_JAEAV?$linked_streambuf@DU?$char_traits@D@std@@@detail@12@PEAD_J@Z)
1>main.cpp.obj : error LNK2019: unresolved external symbol "public: void __cdecl boost::iostreams::detail::gzip_header::reset(void)" (?reset@gzip_header@detail@iostreams@boost@@QEAAXXZ) referenced in function "public: __int64 __cdecl boost::iostreams::basic_gzip_decompressor<class std::allocator<char> >::read<class boost::iostreams::detail::linked_streambuf<char,struct std::char_traits<char> > >(class boost::iostreams::detail::linked_streambuf<char,struct std::char_traits<char> > &,char *,__int64)" (??$read@V?$linked_streambuf@DU?$char_traits@D@std@@@detail@iostreams@boost@@@?$basic_gzip_decompressor@V?$allocator@D@std@@@iostreams@boost@@QEAA_JAEAV?$linked_streambuf@DU?$char_traits@D@std@@@detail@12@PEAD_J@Z)
1>main.cpp.obj : error LNK2019: unresolved external symbol "public: void __cdecl boost::iostreams::detail::gzip_footer::process(char)" (?process@gzip_footer@detail@iostreams@boost@@QEAAXD@Z) referenced in function "public: __int64 __cdecl boost::iostreams::basic_gzip_decompressor<class std::allocator<char> >::read<class boost::iostreams::detail::linked_streambuf<char,struct std::char_traits<char> > >(class boost::iostreams::detail::linked_streambuf<char,struct std::char_traits<char> > &,char *,__int64)" (??$read@V?$linked_streambuf@DU?$char_traits@D@std@@@detail@iostreams@boost@@@?$basic_gzip_decompressor@V?$allocator@D@std@@@iostreams@boost@@QEAA_JAEAV?$linked_streambuf@DU?$char_traits@D@std@@@detail@12@PEAD_J@Z)
1>main.cpp.obj : error LNK2019: unresolved external symbol "public: void __cdecl boost::iostreams::detail::gzip_footer::reset(void)" (?reset@gzip_footer@detail@iostreams@boost@@QEAAXXZ) referenced in function "public: __int64 __cdecl boost::iostreams::basic_gzip_decompressor<class std::allocator<char> >::read<class boost::iostreams::detail::linked_streambuf<char,struct std::char_traits<char> > >(class boost::iostreams::detail::linked_streambuf<char,struct std::char_traits<char> > &,char *,__int64)" (??$read@V?$linked_streambuf@DU?$char_traits@D@std@@@detail@iostreams@boost@@@?$basic_gzip_decompressor@V?$allocator@D@std@@@iostreams@boost@@QEAA_JAEAV?$linked_streambuf@DU?$char_traits@D@std@@@detail@12@PEAD_J@Z)
1>main.cpp.obj : error LNK2001: unresolved external symbol "int const boost::iostreams::zlib::default_compression" (?default_compression@zlib@iostreams@boost@@3HB)
1>main.cpp.obj : error LNK2001: unresolved external symbol "int const boost::iostreams::zlib::deflated" (?deflated@zlib@iostreams@boost@@3HB)
1>main.cpp.obj : error LNK2001: unresolved external symbol "int const boost::iostreams::zlib::default_strategy" (?default_strategy@zlib@iostreams@boost@@3HB)
1>main.cpp.obj : error LNK2001: unresolved external symbol "int const boost::iostreams::zlib::okay" (?okay@zlib@iostreams@boost@@3HB)
1>main.cpp.obj : error LNK2001: unresolved external symbol "int const boost::iostreams::zlib::stream_end" (?stream_end@zlib@iostreams@boost@@3HB)
1>main.cpp.obj : error LNK2001: unresolved external symbol "int const boost::iostreams::zlib::sync_flush" (?sync_flush@zlib@iostreams@boost@@3HB)
1>build\windows\x64\debug\test.exe : fatal error LNK1120: 18 unresolved externals
01Pollux commented 1 month ago

After explicitly handling bzip2 and zlib by adding NO_BZIP2, NO_ZLIB, package:add("deps", *) and config_deppath(file, *), (similar to how is being done to lzma and zstd) the code now compiles and link properly.