我正在使用以下工具集交叉编译项目:
以下列方式配置Boost:
set(CMAKE_CXX_FLAGS ${CMAKE_CPU_FLAGS} "-DBOOST_ALL_DYN_LINK -fPIC -std=gnu++14 ${CMAKE_ARCH}")
set(Boost_DEBUG OFF)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(BOOST_ALL_DYN_LINK ON) # force dynamic linking for all libraries
set(BOOST_COMPONENTS
system
thread
program_options
regex
filesystem
unit_test_framework
date_time
chrono
log_setup
log
)
set(BOOST_ROOT ${CMAKE_SYSROOT})
set(BOOST_INCLUDEDIR ${BOOST_ROOT}/usr/inc)
set(BOOST_LIBRARYDIR ${BOOST_ROOT}/usr/lib/arm-linux-gnueabihf)
find_package(Boost 1.54.0 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
在OS X编译和链接下运行正常,我可以将应用程序发送到RPI2并运行它。
问题在于Ubuntu下的链接过程。它无法找到与boost.log相关的几个符号:
logger/liblogger.a(logger.cpp.o): In function `boost::log::v2_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> >& boost::log::v2_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> >::formatted_write<wchar_t>(wchar_t const*, int)':
logger.cpp:(.text._ZN5boost3log11v2_mt_posix24basic_formatting_ostreamIcSt11char_traitsIcESaIcEE15formatted_writeIwEERS6_PKT_i[_ZN5boost3log11v2_mt_posix24basic_formatting_ostreamIcSt11char_traitsIcESaIcEE15formatted_writeIwEERS6_PKT_i]+0x76): undefined reference to `boost::log::v2_mt_posix::aux::code_convert(wchar_t const*, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::locale const&)'
logger/liblogger.a(logger.cpp.o): In function `void boost::log::v2_mt_posix::basic_formatting_ostream<char, std::char_traits<char>, std::allocator<char> >::aligned_write<wchar_t>(wchar_t const*, int)':
logger.cpp:(.text._ZN5boost3log11v2_mt_posix24basic_formatting_ostreamIcSt11char_traitsIcESaIcEE13aligned_writeIwEEvPKT_i[_ZN5boost3log11v2_mt_posix24basic_formatting_ostreamIcSt11char_traitsIcESaIcEE13aligned_writeIwEEvPKT_i]+0x6c): undefined reference to `boost::log::v2_mt_posix::aux::code_convert(wchar_t const*, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::locale const&)'
logger.cpp:(.text._ZN5boost3log11v2_mt_posix24basic_formatting_ostreamIcSt11char_traitsIcESaIcEE13aligned_writeIwEEvPKT_i[_ZN5boost3log11v2_mt_posix24basic_formatting_ostreamIcSt11char_traitsIcESaIcEE13aligned_writeIwEEvPKT_i]+0xc6): undefined reference to `boost::log::v2_mt_posix::aux::code_convert(wchar_t const*, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::locale const&)'
logger/liblogger.a(logger.cpp.o): In function `void boost::log::v2_mt_posix::sinks::basic_formatting_sink_frontend<char>::feed_record<boost::mutex, boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char> >(boost::log::v2_mt_posix::record_view const&, boost::mutex&, boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char>&)':
logger.cpp:(.text._ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS_5mutexENS2_26basic_text_ostream_backendIcEEEEvRKNS1_11record_viewERT_RT0_[_ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS_5mutexENS2_26basic_text_ostream_backendIcEEEEvRKNS1_11record_viewERT_RT0_]+0xda): undefined reference to `boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char>::consume(boost::log::v2_mt_posix::record_view const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
logger/liblogger.a(logger.cpp.o): In function `void boost::log::v2_mt_posix::sinks::basic_formatting_sink_frontend<char>::feed_record<boost::mutex, boost::log::v2_mt_posix::sinks::text_file_backend>(boost::log::v2_mt_posix::record_view const&, boost::mutex&, boost::log::v2_mt_posix::sinks::text_file_backend&)':
logger.cpp:(.text._ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS_5mutexENS2_17text_file_backendEEEvRKNS1_11record_viewERT_RT0_[_ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS_5mutexENS2_17text_file_backendEEEvRKNS1_11record_viewERT_RT0_]+0xda): undefined reference to `boost::log::v2_mt_posix::sinks::text_file_backend::consume(boost::log::v2_mt_posix::record_view const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
logger/liblogger.a(logger.cpp.o): In function `void boost::log::v2_mt_posix::sinks::basic_formatting_sink_frontend<char>::feed_record<boost::log::v2_mt_posix::aux::fake_mutex, boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char> >(boost::log::v2_mt_posix::record_view const&, boost::log::v2_mt_posix::aux::fake_mutex&, boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char>&)':
logger.cpp:(.text._ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS1_3aux10fake_mutexENS2_26basic_text_ostream_backendIcEEEEvRKNS1_11record_viewERT_RT0_[_ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS1_3aux10fake_mutexENS2_26basic_text_ostream_backendIcEEEEvRKNS1_11record_viewERT_RT0_]+0xda): undefined reference to `boost::log::v2_mt_posix::sinks::basic_text_ostream_backend<char>::consume(boost::log::v2_mt_posix::record_view const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
logger/liblogger.a(logger.cpp.o): In function `void boost::log::v2_mt_posix::sinks::basic_formatting_sink_frontend<char>::feed_record<boost::log::v2_mt_posix::aux::fake_mutex, boost::log::v2_mt_posix::sinks::text_file_backend>(boost::log::v2_mt_posix::record_view const&, boost::log::v2_mt_posix::aux::fake_mutex&, boost::log::v2_mt_posix::sinks::text_file_backend&)':
logger.cpp:(.text._ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS1_3aux10fake_mutexENS2_17text_file_backendEEEvRKNS1_11record_viewERT_RT0_[_ZN5boost3log11v2_mt_posix5sinks30basic_formatting_sink_frontendIcE11feed_recordINS1_3aux10fake_mutexENS2_17text_file_backendEEEvRKNS1_11record_viewERT_RT0_]+0xda): undefined reference to `boost::log::v2_mt_posix::sinks::text_file_backend::consume(boost::log::v2_mt_posix::record_view const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
使用:
make VERBOSE=1
似乎所有图书馆都在那里
/usr/local/gcc-linaro-5.1-2015.08-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++ --sysroot=/home/amr/iot_hub/3rd-party/rpi2_sysroot -DBOOST_ALL_DYN_LINK -fPIC -std=gnu++14 -march=armv7-a -mtune=cortex-a7 -mfpu=vfp -mfloat-abi=hard -Wl,-rpath-link=/home/amr/iot_hub/3rd-party/rpi2_sysroot/lib/arm-linux-gnueabihf -Wl,-rpath-link=/home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf CMakeFiles/hub.dir/main/main.cpp.o -o hub -L/home/amr/iot_hub/3rd-party/rpi2_sysroot/lib/arm-linux-gnueabihf -L/home/amr/iot_hub/3rd-party/rpi2_sysroot/lib -L/home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib -L/home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf -L/home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/gcc/arm-linux-gnueabihf/5 -rdynamic sensor-framework/libsensor-framework.a transport-framework/libtransport-framework.a tools/libtools.a logger/liblogger.a database-connector/libdb-conn.a -lbluetooth /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libsoci_core.so /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libsoci_postgresql.so -lpq -lpthread /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libboost_program_options.so /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libboost_system.so /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libboost_thread.so /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libboost_regex.so /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libboost_filesystem.so /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libboost_unit_test_framework.so /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libboost_date_time.so /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libboost_chrono.so /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libboost_log.so /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libboost_log_setup.so /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libssl.so /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libcrypto.so /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libglib-2.0.a /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libgthread-2.0.so /home/amr/iot_hub/3rd-party/rpi2_sysroot/usr/lib/arm-linux-gnueabihf/libgmodule-2.0.so sensor-framework/libsensor-framework.a -Wl,-rpath,/lib/arm-linux-gnueabihf:/lib:/usr/lib:/usr/lib/arm-linux-gnueabihf:/usr/lib/gcc/arm-linux-gnueabihf/5:
这个问题的根本原因是什么?
答案 0 :(得分:0)
找到一些解决方法。 我在OS X(4.9)和Ubuntu(5.1)上使用不同的工具链,这似乎在链接过程中产生了一些差异(或者没有二进制兼容性)。在Ubuntu上使用与OS X相同的版本安装linaro工具链已经解决了这个问题。