Boost BZip2 未定义参考错误

问题描述 投票:0回答:1

链接测试时出现以下错误。我有一个静态库:coje,它链接包含的库,然后我的测试文件夹被通配,并为每个

.cpp
文件创建一个测试。我还为每个测试链接了 coje 的库。

我尝试了不同的库链接顺序,但没有成功。我在这里做错了什么?

Consolidate compiler generated dependencies of target BZip2Test
[ 90%] Linking CXX executable bin/BZip2Test
/usr/bin/ld: bin/libcoje.a(BZip.cpp.o): in function `boost::iostreams::detail::bzip2_compressor_impl<std::allocator<char> >::bzip2_compressor_impl(boost::iostreams::bzip2_params const&)':
/home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:317: undefined reference to `boost::iostreams::detail::bzip2_base::bzip2_base(boost::iostreams::bzip2_params const&)'
/usr/bin/ld: bin/libcoje.a(BZip.cpp.o): in function `boost::iostreams::detail::bzip2_compressor_impl<std::allocator<char> >::~bzip2_compressor_impl()':
/home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:321: undefined reference to `boost::iostreams::detail::bzip2_base::end(bool, std::nothrow_t)'
/usr/bin/ld: /home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:321: undefined reference to `boost::iostreams::detail::bzip2_base::~bzip2_base()'
/usr/bin/ld: bin/libcoje.a(BZip.cpp.o): in function `boost::iostreams::detail::bzip2_decompressor_impl<std::allocator<char> >::bzip2_decompressor_impl(bool)':
/home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:357: undefined reference to `boost::iostreams::detail::bzip2_base::bzip2_base(boost::iostreams::bzip2_params const&)'
/usr/bin/ld: bin/libcoje.a(BZip.cpp.o): in function `boost::iostreams::detail::bzip2_decompressor_impl<std::allocator<char> >::~bzip2_decompressor_impl()':
/home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:361: undefined reference to `boost::iostreams::detail::bzip2_base::end(bool, std::nothrow_t)'
/usr/bin/ld: /home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:361: undefined reference to `boost::iostreams::detail::bzip2_base::~bzip2_base()'
/usr/bin/ld: bin/libcoje.a(BZip.cpp.o): in function `boost::iostreams::detail::bzip2_compressor_impl<std::allocator<char> >::filter(char const*&, char const*, char*&, char*, bool)':
/home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:330: undefined reference to `boost::iostreams::detail::bzip2_base::before(char const*&, char const*, char*&, char*)'
/usr/bin/ld: /home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:331: undefined reference to `boost::iostreams::bzip2::finish'
/usr/bin/ld: /home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:331: undefined reference to `boost::iostreams::bzip2::run'
/usr/bin/ld: /home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:331: undefined reference to `boost::iostreams::detail::bzip2_base::compress(int)'
/usr/bin/ld: /home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:332: undefined reference to `boost::iostreams::detail::bzip2_base::after(char const*&, char*&)'
/usr/bin/ld: /home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:333: undefined reference to `boost::iostreams::bzip2_error::check(int)'
/usr/bin/ld: /home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:334: undefined reference to `boost::iostreams::bzip2::stream_end'
/usr/bin/ld: bin/libcoje.a(BZip.cpp.o): in function `boost::iostreams::detail::bzip2_decompressor_impl<std::allocator<char> >::filter(char const*&, char const*, char*&, char*, bool)':
/home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:378: undefined reference to `boost::iostreams::detail::bzip2_base::before(char const*&, char const*, char*&, char*)'
/usr/bin/ld: /home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:379: undefined reference to `boost::iostreams::detail::bzip2_base::decompress()'
/usr/bin/ld: /home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:380: undefined reference to `boost::iostreams::bzip2::ok'
/usr/bin/ld: /home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:381: undefined reference to `boost::iostreams::detail::bzip2_base::check_end(char const*, char const*)'
/usr/bin/ld: /home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:382: undefined reference to `boost::iostreams::detail::bzip2_base::after(char const*&, char*&)'
/usr/bin/ld: /home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:383: undefined reference to `boost::iostreams::bzip2_error::check(int)'
/usr/bin/ld: /home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:384: undefined reference to `boost::iostreams::bzip2::stream_end'
/usr/bin/ld: bin/libcoje.a(BZip.cpp.o): in function `boost::iostreams::detail::bzip2_decompressor_impl<std::allocator<char> >::close()':
/home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:393: undefined reference to `boost::iostreams::detail::bzip2_base::end(bool)'
/usr/bin/ld: bin/libcoje.a(BZip.cpp.o): in function `void boost::iostreams::detail::bzip2_base::init<std::allocator<char> >(bool, boost::iostreams::detail::bzip2_allocator<std::allocator<char>, boost::iostreams::detail::bzip2_allocator_traits<std::allocator<char> >::type>&)':
/home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:167: undefined reference to `boost::iostreams::detail::bzip2_base::do_init(bool, void* (*)(void*, int, int), void (*)(void*, void*), void*)'
/usr/bin/ld: bin/libcoje.a(BZip.cpp.o): in function `boost::iostreams::detail::bzip2_compressor_impl<std::allocator<char> >::close()':
/home/ubuntu/Projects/coje/build/_deps/boost-src/boost/iostreams/filter/bzip2.hpp:341: undefined reference to `boost::iostreams::detail::bzip2_base::end(bool)'
collect2: error: ld returned 1 exit status

CMakeLists.txt

  add_executable(${TEST_NAME} ${TEST_SOURCES})
  target_link_libraries(${TEST_NAME} Boost::boost Boost::iostreams)
  target_link_libraries(${TEST_NAME} ${COJE_LIBRARY})
  if(ANDROID)
   target_link_libraries(${TEST_NAME} android log openssl::ssl openssl::crypto bcrypt)
   target_link_libraries(${TEST_NAME} vulkan shaderc_shared)
   target_link_libraries(${TEST_NAME} EGL GLESv1_CM GLESv2 GLESv3)
  elseif(UNIX)
   target_link_libraries(${TEST_NAME} X11 Xrandr Xext Xfixes xkbcommon Xrender ssl crypto SQLite_ORM bcrypt ${AWSSDK_LIBRARIES} portaudio)
   target_link_libraries(${TEST_NAME} vulkan shaderc_shared)
   target_link_libraries(${TEST_NAME} GL)
  endif()
  # add firebase libraries
  target_link_libraries(${TEST_NAME}
                        firebase_functions
                        firebase_firestore
                        firebase_auth
                        firebase_app
                        firebase_gma
                        firebase_installations
                        firebase_messaging
                        firebase_remote_config
                        firebase_storage
                        firebase_analytics
                        firebase_app_check
                        firebase_dynamic_links
                        )
  # add aws SDK libraries
  target_link_libraries(${TEST_NAME} aws-cpp-sdk-s3)
  # other libraries
  target_link_libraries(${TEST_NAME} qrcodegen libnyquist ${LIBSAMPLERATE_LIBRARY} tbb freetype cpptrace assimp tiny-aes)

cojeLibraryConfig.cmake

add_library(coje
            STATIC
            ${COJE_SOURCES}
            ${COJE_SRC_DIR}/vendor/ttf2mesh/ttf2mesh.c
            ${COJE_SRC_DIR}/vendor/SHA/src/SHA256.cpp
            ${COJE_SRC_DIR}/vendor/SHA/src/SHA384.cpp
            ${COJE_SRC_DIR}/vendor/SHA/src/SHA512.cpp
            )
set(COJE_LIBRARY coje)
target_link_libraries(coje Boost::boost Boost::iostreams)
if(ANDROID)
 target_link_libraries(coje android log openssl::ssl openssl::crypto bcrypt)
 target_link_libraries(coje vulkan shaderc_shared)
 target_link_libraries(coje EGL GLESv1_CM GLESv2 GLESv3)
elseif(UNIX)
 target_link_libraries(coje X11 Xrandr Xext Xfixes xkbcommon Xrender ssl crypto SQLite_ORM bcrypt ${AWSSDK_LIBRARIES} portaudio)
 target_link_libraries(coje vulkan shaderc_shared)
 target_link_libraries(coje GL)
endif()
# add firebase libraries
target_link_libraries(coje
                      firebase_functions
                      firebase_firestore
                      firebase_auth
                      firebase_app
                      firebase_gma
                      firebase_installations
                      firebase_messaging
                      firebase_remote_config
                      firebase_storage
                      firebase_analytics
                      firebase_app_check
                      firebase_dynamic_links
                      )
# add aws SDK libraries
target_link_libraries(coje aws-cpp-sdk-s3)
# other libraries
target_link_libraries(coje qrcodegen libnyquist ${LIBSAMPLERATE_LIBRARY} tbb freetype cpptrace assimp tiny-aes)
c++ cmake boost
1个回答
0
投票

这是在 AWS Ubuntu Linux 实例上,我正在使用包

boost-cmake
获取 boost。这对于 Android 来说效果很好,但是我的开发 PC 和 AWS 实例之间的一个关键区别是,在我的开发 PC 上,我安装了 libboost-dev 软件包,而不是在实例上。

发布我的链接器后,链接的是

.so
中找到的 boost
libboost-dev
文件,而不是
.a
中的静态
boost-cmake
文件,我对我的 cmake 构建进行了更改,以便在 UNIX 构建(可能是 Windows 和 Windows)上使用
find_package(Boost COMPONENTS iostreams)
Mac 系统也是如此)。

这修复了我在 aws 实例上的构建。嗯,我认为会的,构建完成时会确认

© www.soinside.com 2019 - 2024. All rights reserved.