我已经编译了 boost,cmake 工作,一切都接近工作了,但是最简单的示例(琐碎的日志记录)无法编译,并出现链接器错误。我真的不知道该怎么办。
这是我当前的 CMake 设置
FIND_PACKAGE(Boost 1.54.0 COMPONENTS log log_setup REQUIRED)
...
TARGET_LINK_LIBRARIES(cogtd ${LIBS} ${SDL2_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
这是错误日志
C:\MingW64\mingw64\bin\g++.exe -std=c++11 -g -mwindows -Wl,--whole-archive CMakeFiles\cogtd.dir/objects.a -Wl,--no-whole-archive -o cogtd.exe -Wl,--out-implib,libcogtd.dll.a -Wl,--major-image-version,0,--minor-image-version,0 C:\boost_1_54_0\stage\lib\libboost_log-mgw48-mt-d-1_54.dll C:\boost_1_54_0\stage\lib\libboost_log_setup-mgw48-mt-1_54.dll SDLHelper\libSDLHelper.a Event\libEvent.a Component\libComponent.a Error\libError.a -lmingw32 C:\SDL2-2.0.0\x86_64-w64-mingw32\lib\libSDL2main.a C:\SDL2-2.0.0\x86_64-w64-mingw32\lib\libSDL2.dll.a C:\boost_1_54_0\stage\lib\libboost_log-mgw48-mt-d-1_54.dll C:\boost_1_54_0\stage\lib\libboost_log_setup-mgw48-mt-1_54.dll -lmingw32 C:\SDL2-2.0.0\x86_64-w64-mingw32\lib\libSDL2main.a C:\SDL2-2.0.0\x86_64-w64-mingw32\lib\libSDL2.dll.a -lstdc++ -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `SDL_main':
C:\cygwin\home\Cogman\cogtd\build\src/../../src/main.cxx:53: undefined reference to `boost::log::v2s_mt_nt5::trivial::logger::get()'
C:\cygwin\home\Cogman\cogtd\build\src/../../src/main.cxx:53: undefined reference to `boost::log::v2s_mt_nt5::trivial::logger::get()'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::record::reset()':
C:/boost_1_54_0/boost/log/core/record.hpp:153: undefined reference to `boost::log::v2s_mt_nt5::record_view::public_data::destroy(boost::log::v2s_mt_nt5::record_view::public_data const*)'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::record boost::log::v2s_mt_nt5::sources::basic_composite_logger<char, boost::log::v2s_mt_nt5::sources::severity_logger_mt<boost::log::v2s_mt_nt5::trivial::severity_level>, boost::log::v2s_mt_nt5::sources::multi_thread_model<boost::log::v2s_mt_nt5::aux::light_rw_mutex>, boost::log::v2s_mt_nt5::sources::features<boost::log::v2s_mt_nt5::sources::severity<boost::log::v2s_mt_nt5::trivial::severity_level> > >::open_record<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_nt5::keywords::tag::severity, boost::log::v2s_mt_nt5::trivial::severity_level const> >(boost::parameter::aux::tagged_argument<boost::log::v2s_mt_nt5::keywords::tag::severity, boost::log::v2s_mt_nt5::trivial::severity_level const> const&)':
C:/boost_1_54_0/boost/log/sources/basic_logger.hpp:457: undefined reference to `boost::log::v2s_mt_nt5::core::get_logging_enabled() const'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::aux::record_pump<boost::log::v2s_mt_nt5::sources::severity_logger_mt<boost::log::v2s_mt_nt5::trivial::severity_level> >::~record_pump()':
C:/boost_1_54_0/boost/log/sources/record_ostream.hpp:278: undefined reference to `boost::log::v2s_mt_nt5::aux::unhandled_exception_count()'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::aux::record_pump<boost::log::v2s_mt_nt5::sources::severity_logger_mt<boost::log::v2s_mt_nt5::trivial::severity_level> >::record_pump(boost::log::v2s_mt_nt5::sources::severity_logger_mt<boost::log::v2s_mt_nt5::trivial::severity_level>&, boost::log::v2s_mt_nt5::record&)':
C:/boost_1_54_0/boost/log/sources/record_ostream.hpp:258: undefined reference to `boost::log::v2s_mt_nt5::aux::stream_provider<char>::allocate_compound(boost::log::v2s_mt_nt5::record&)'
C:/boost_1_54_0/boost/log/sources/record_ostream.hpp:259: undefined reference to `boost::log::v2s_mt_nt5::aux::unhandled_exception_count()'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::aux::record_pump<boost::log::v2s_mt_nt5::sources::severity_logger_mt<boost::log::v2s_mt_nt5::trivial::severity_level> >::auto_release::~auto_release()':
C:/boost_1_54_0/boost/log/sources/record_ostream.hpp:243: undefined reference to `boost::log::v2s_mt_nt5::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_nt5::aux::stream_provider<char>::stream_compound*)'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::sources::multi_thread_model<boost::log::v2s_mt_nt5::aux::light_rw_mutex>::lock_shared() const':
C:/boost_1_54_0/boost/log/sources/threading_models.hpp:74: undefined reference to `boost::log::v2s_mt_nt5::aux::light_rw_mutex::lock_shared()'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::sources::multi_thread_model<boost::log::v2s_mt_nt5::aux::light_rw_mutex>::unlock_shared() const':
C:/boost_1_54_0/boost/log/sources/threading_models.hpp:78: undefined reference to `boost::log::v2s_mt_nt5::aux::light_rw_mutex::unlock_shared()'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::sources::aux::severity_level<boost::log::v2s_mt_nt5::trivial::severity_level>::set_value(boost::log::v2s_mt_nt5::trivial::severity_level)':
C:/boost_1_54_0/boost/log/sources/severity_feature.hpp:135: undefined reference to `boost::log::v2s_mt_nt5::sources::aux::get_severity_level()'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::record boost::log::v2s_mt_nt5::sources::basic_logger<char, boost::log::v2s_mt_nt5::sources::severity_logger_mt<boost::log::v2s_mt_nt5::trivial::severity_level>, boost::log::v2s_mt_nt5::sources::multi_thread_model<boost::log::v2s_mt_nt5::aux::light_rw_mutex> >::open_record_unlocked<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_nt5::keywords::tag::severity, boost::log::v2s_mt_nt5::trivial::severity_level const> >(boost::parameter::aux::tagged_argument<boost::log::v2s_mt_nt5::keywords::tag::severity, boost::log::v2s_mt_nt5::trivial::severity_level const> const&)':
C:/boost_1_54_0/boost/log/sources/basic_logger.hpp:260: undefined reference to `boost::log::v2s_mt_nt5::core::open_record(boost::log::v2s_mt_nt5::attribute_set const&)'
CMakeFiles\cogtd.dir/objects.a(main.cxx.obj): In function `boost::log::v2s_mt_nt5::core::push_record(boost::log::v2s_mt_nt5::record&&)':
C:/boost_1_54_0/boost/log/core/core.hpp:308: undefined reference to `boost::log::v2s_mt_nt5::core::push_record_move(boost::log::v2s_mt_nt5::record&)'
collect2.exe: error: ld returned 1 exit status
src\CMakeFiles\cogtd.dir\build.make:130: recipe for target 'src/cogtd.exe' failed
make.exe[2]: *** [src/cogtd.exe] Error 1
make.exe[2]: Leaving directory 'C:/cygwin/home/Cogman/cogtd/build'
CMakeFiles\Makefile2:94: recipe for target 'src/CMakeFiles/cogtd.dir/all' failed
make.exe[1]: *** [src/CMakeFiles/cogtd.dir/all] Error 2
make.exe[1]: Leaving directory 'C:/cygwin/home/Cogman/cogtd/build'
Makefile:118: recipe for target 'all' failed
make.exe: *** [all] Error 2
Boost 被编译为使用动态库。
我正在使用 Boost-1.54、Mingw-w64 4.8.1 rev 5(x64 seh posix 版本)和 Cmake 2.8.11 我试过静态链接无济于事。