Я пытаюсь взять простой обучающий файл boost.asio daytime6, который отлично работает, и добавить простой регистратор boost.log, взятый из примера settings_file. Код выглядит так:
//
// server.cpp
// ~~~~~~~~~~
//
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <ctime>
#include <iostream>
#include <string>
#include <exception>
#include <fstream>
#include <boost/array.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/asio.hpp>
#include <boost/log/common.hpp>
#include <boost/log/attributes.hpp>
#include <boost/log/utility/setup/from_stream.hpp>
namespace logging = boost::log;
namespace attrs = boost::log::attributes;
namespace src = boost::log::sources;
using boost::asio::ip::udp;
enum severity_level
{
normal,
notification,
warning,
error,
critical
};
BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(my_logger, src::severity_logger< >)
std::string make_daytime_string()
{
using namespace std; // For time_t, time and ctime;
time_t now = time(0);
return ctime(&now);
}
class udp_server
{
public:
udp_server(boost::asio::io_service& io_service)
: socket_(io_service, udp::endpoint(udp::v4(), 4221))
{
start_receive();
}
private:
void start_receive()
{
socket_.async_receive_from(
boost::asio::buffer(recv_buffer_), remote_endpoint_,
boost::bind(&udp_server::handle_receive, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
}
void handle_receive(const boost::system::error_code& error,
std::size_t /*bytes_transferred*/)
{
if (!error || error == boost::asio::error::message_size)
{
boost::shared_ptr<std::string> message(
new std::string(make_daytime_string()));
socket_.async_send_to(boost::asio::buffer(*message), remote_endpoint_,
boost::bind(&udp_server::handle_send, this, message,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
start_receive();
}
}
void handle_send(boost::shared_ptr<std::string> /*message*/,
const boost::system::error_code& /*error*/,
std::size_t /*bytes_transferred*/)
{
}
udp::socket socket_;
udp::endpoint remote_endpoint_;
boost::array<char, 1> recv_buffer_;
};
int main()
{
try
{
src::severity_logger< >& lg = my_logger::get();
BOOST_LOG_SEV(lg, normal) << "This is a normal severity record";
std::cout << "utp server started port:4221 \n" << std::endl;
boost::asio::io_service io_service;
udp_server server(io_service);
io_service.run();
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
return 0;
}
Библиотеки ссылок:
libboost_iostreams-vc120-mt-sgd-1_61.lib;libboost_regex-vc120-mt-sgd-1_61.lib;libboost_system-vc120-mt-sgd-1_61.lib;libboost_thread-vc120-mt-sgd-1_61.lib;libboost_timer-vc120-mt-sgd-1_61.lib;libboost_date_time-vc120-mt-sgd-1_61.lib;libboost_filesystem-vc120-mt-sgd-1_61.lib;libboost_atomic-vc120-mt-sgd-1_61.lib;libboost_log_setup-vc120-mt-sgd-1_61.lib;%(AdditionalDependencies)
флаги препроцессора:
WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=0x0501;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)
в соответствии с этой веткой:
Ошибка компоновщика Boost-log
я проверил, он установлен на Да (/Zc:wchar_t), и это так.
но я все еще получаю эти ошибки связывания:
1>net_udp_server.obj : error LNK2019: unresolved external symbol "public: static void * __cdecl boost::log::v2s_mt_nt5::attribute::impl::operator new(unsigned int)" (??2impl@attribute@v2s_mt_nt5@log@boost@@SAPAXI@Z) referenced in function "public: __thiscall boost::log::v2s_mt_nt5::sources::aux::severity_level<int>::severity_level<int>(void)" (??0?$severity_level@H@aux@sources@v2s_mt_nt5@log@boost@@QAE@XZ)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "public: static void __cdecl boost::log::v2s_mt_nt5::attribute::impl::operator delete(void *,unsigned int)" (??3impl@attribute@v2s_mt_nt5@log@boost@@SAXPAXI@Z) referenced in function __unwindfunclet$??0?$severity_level@H@aux@sources@v2s_mt_nt5@log@boost@@QAE@XZ$0
1>net_udp_server.obj : error LNK2019: unresolved external symbol "public: __thiscall boost::log::v2s_mt_nt5::attribute_set::attribute_set(void)" (??0attribute_set@v2s_mt_nt5@log@boost@@QAE@XZ) referenced in function "public: __thiscall boost::log::v2s_mt_nt5::sources::basic_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model>::basic_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model>(void)" (??0?$basic_logger@DV?$severity_logger@H@sources@v2s_mt_nt5@log@boost@@Usingle_thread_model@2345@@sources@v2s_mt_nt5@log@boost@@QAE@XZ)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "public: __thiscall boost::log::v2s_mt_nt5::attribute_set::attribute_set(class boost::log::v2s_mt_nt5::attribute_set const &)" (??0attribute_set@v2s_mt_nt5@log@boost@@QAE@ABV0123@@Z) referenced in function "public: __thiscall boost::log::v2s_mt_nt5::sources::basic_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model>::basic_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model>(class boost::log::v2s_mt_nt5::sources::basic_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model> const &)" (??0?$basic_logger@DV?$severity_logger@H@sources@v2s_mt_nt5@log@boost@@Usingle_thread_model@2345@@sources@v2s_mt_nt5@log@boost@@QAE@ABV01234@@Z)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "public: __thiscall boost::log::v2s_mt_nt5::attribute_set::~attribute_set(void)" (??1attribute_set@v2s_mt_nt5@log@boost@@QAE@XZ) referenced in function "public: __thiscall boost::log::v2s_mt_nt5::sources::basic_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model>::~basic_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model>(void)" (??1?$basic_logger@DV?$severity_logger@H@sources@v2s_mt_nt5@log@boost@@Usingle_thread_model@2345@@sources@v2s_mt_nt5@log@boost@@QAE@XZ)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "public: struct std::pair<class boost::log::v2s_mt_nt5::attribute_set::iter<0>,bool> __thiscall boost::log::v2s_mt_nt5::attribute_set::insert(class boost::log::v2s_mt_nt5::attribute_name,class boost::log::v2s_mt_nt5::attribute const &)" (?insert@attribute_set@v2s_mt_nt5@log@boost@@QAE?AU?$pair@V?$iter@$0A@@attribute_set@v2s_mt_nt5@log@boost@@_N@std@@Vattribute_name@234@ABVattribute@234@@Z) referenced in function "public: class boost::log::v2s_mt_nt5::attribute & __thiscall boost::log::v2s_mt_nt5::aux::attribute_set_reference_proxy::operator=(class boost::log::v2s_mt_nt5::attribute const &)const " (??4attribute_set_reference_proxy@aux@v2s_mt_nt5@log@boost@@QBEAAVattribute@234@ABV5234@@Z)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "public: static void __cdecl boost::log::v2s_mt_nt5::record_view::public_data::destroy(struct boost::log::v2s_mt_nt5::record_view::public_data const *)" (?destroy@public_data@record_view@v2s_mt_nt5@log@boost@@SAXPBU12345@@Z) referenced in function "public: void __thiscall boost::log::v2s_mt_nt5::record::reset(void)" (?reset@record@v2s_mt_nt5@log@boost@@QAEXXZ)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "public: static class boost::shared_ptr<class boost::log::v2s_mt_nt5::core> __cdecl boost::log::v2s_mt_nt5::core::get(void)" (?get@core@v2s_mt_nt5@log@boost@@SA?AV?$shared_ptr@Vcore@v2s_mt_nt5@log@boost@@@4@XZ) referenced in function "public: __thiscall boost::log::v2s_mt_nt5::sources::basic_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model>::basic_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model>(class boost::log::v2s_mt_nt5::sources::basic_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model> const &)" (??0?$basic_logger@DV?$severity_logger@H@sources@v2s_mt_nt5@log@boost@@Usingle_thread_model@2345@@sources@v2s_mt_nt5@log@boost@@QAE@ABV01234@@Z)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "public: bool __thiscall boost::log::v2s_mt_nt5::core::get_logging_enabled(void)const " (?get_logging_enabled@core@v2s_mt_nt5@log@boost@@QBE_NXZ) referenced in function "public: class boost::log::v2s_mt_nt5::record __thiscall boost::log::v2s_mt_nt5::sources::basic_composite_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model,struct boost::log::v2s_mt_nt5::sources::features<struct boost::log::v2s_mt_nt5::sources::severity<int> > >::open_record<struct boost::parameter::aux::tagged_argument<struct boost::log::v2s_mt_nt5::keywords::tag::severity,enum severity_level const > >(struct boost::parameter::aux::tagged_argument<struct boost::log::v2s_mt_nt5::keywords::tag::severity,enum severity_level const > const &)" (??$open_record@U?$tagged_argument@Useverity@tag@keywords@v2s_mt_nt5@log@boost@@$$CBW4severity_level@@@aux@parameter@boost@@@?$basic_composite_logger@DV?$severity_logger@H@sources@v2s_mt_nt5@log@boost@@Usingle_thread_model@2345@U?$features@U?$severity@H@sources@v2s_mt_nt5@log@boost@@@2345@@sources@v2s_mt_nt5@log@boost@@QAE?AVrecord@234@ABU?$tagged_argument@Useverity@tag@keywords@v2s_mt_nt5@log@boost@@$$CBW4severity_level@@@aux@parameter@4@@Z)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "public: class boost::log::v2s_mt_nt5::record __thiscall boost::log::v2s_mt_nt5::core::open_record(class boost::log::v2s_mt_nt5::attribute_set const &)" (?open_record@core@v2s_mt_nt5@log@boost@@QAE?AVrecord@234@ABVattribute_set@234@@Z) referenced in function "protected: class boost::log::v2s_mt_nt5::record __thiscall boost::log::v2s_mt_nt5::sources::basic_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model>::open_record_unlocked<struct boost::parameter::aux::tagged_argument<struct boost::log::v2s_mt_nt5::keywords::tag::severity,enum severity_level const > >(struct boost::parameter::aux::tagged_argument<struct boost::log::v2s_mt_nt5::keywords::tag::severity,enum severity_level const > const &)" (??$open_record_unlocked@U?$tagged_argument@Useverity@tag@keywords@v2s_mt_nt5@log@boost@@$$CBW4severity_level@@@aux@parameter@boost@@@?$basic_logger@DV?$severity_logger@H@sources@v2s_mt_nt5@log@boost@@Usingle_thread_model@2345@@sources@v2s_mt_nt5@log@boost@@IAE?AVrecord@234@ABU?$tagged_argument@Useverity@tag@keywords@v2s_mt_nt5@log@boost@@$$CBW4severity_level@@@aux@parameter@4@@Z)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "private: void __thiscall boost::log::v2s_mt_nt5::core::push_record_move(class boost::log::v2s_mt_nt5::record &)" (?push_record_move@core@v2s_mt_nt5@log@boost@@AAEXAAVrecord@234@@Z) referenced in function "public: void __thiscall boost::log::v2s_mt_nt5::core::push_record(class boost::log::v2s_mt_nt5::record &&)" (?push_record@core@v2s_mt_nt5@log@boost@@QAEX$$QAVrecord@234@@Z)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "public: void __thiscall boost::log::v2s_mt_nt5::aux::once_block_sentry::commit(void)" (?commit@once_block_sentry@aux@v2s_mt_nt5@log@boost@@QAEXXZ) referenced in function "public: static class boost::shared_ptr<struct boost::log::v2s_mt_nt5::sources::aux::logger_holder<class boost::log::v2s_mt_nt5::sources::severity_logger<int> > > & __cdecl boost::log::v2s_mt_nt5::aux::lazy_singleton<struct boost::log::v2s_mt_nt5::sources::aux::logger_singleton<struct my_logger>,class boost::shared_ptr<struct boost::log::v2s_mt_nt5::sources::aux::logger_holder<class boost::log::v2s_mt_nt5::sources::severity_logger<int> > > >::get(void)" (?get@?$lazy_singleton@U?$logger_singleton@Umy_logger@@@aux@sources@v2s_mt_nt5@log@boost@@V?$shared_ptr@U?$logger_holder@V?$severity_logger@H@sources@v2s_mt_nt5@log@boost@@@aux@sources@v2s_mt_nt5@log@boost@@@6@@aux@v2s_mt_nt5@log@boost@@SAAAV?$shared_ptr@U?$logger_holder@V?$severity_logger@H@sources@v2s_mt_nt5@log@boost@@@aux@sources@v2s_mt_nt5@log@boost@@@5@XZ)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "private: bool __thiscall boost::log::v2s_mt_nt5::aux::once_block_sentry::enter_once_block(void)const " (?enter_once_block@once_block_sentry@aux@v2s_mt_nt5@log@boost@@ABE_NXZ) referenced in function "public: bool __thiscall boost::log::v2s_mt_nt5::aux::once_block_sentry::executed(void)const " (?executed@once_block_sentry@aux@v2s_mt_nt5@log@boost@@QBE_NXZ)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "private: void __thiscall boost::log::v2s_mt_nt5::aux::once_block_sentry::rollback(void)" (?rollback@once_block_sentry@aux@v2s_mt_nt5@log@boost@@AAEXXZ) referenced in function "public: __thiscall boost::log::v2s_mt_nt5::aux::once_block_sentry::~once_block_sentry(void)" (??1once_block_sentry@aux@v2s_mt_nt5@log@boost@@QAE@XZ)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "public: static class boost::shared_ptr<struct boost::log::v2s_mt_nt5::sources::aux::logger_holder_base> __cdecl boost::log::v2s_mt_nt5::sources::aux::global_storage::get_or_init(class boost::typeindex::stl_type_index,class boost::shared_ptr<struct boost::log::v2s_mt_nt5::sources::aux::logger_holder_base> (__cdecl*)(void))" (?get_or_init@global_storage@aux@sources@v2s_mt_nt5@log@boost@@SA?AV?$shared_ptr@Ulogger_holder_base@aux@sources@v2s_mt_nt5@log@boost@@@6@Vstl_type_index@typeindex@6@P6A?AV76@XZ@Z) referenced in function "public: static void __cdecl boost::log::v2s_mt_nt5::sources::aux::logger_singleton<struct my_logger>::init_instance(void)" (?init_instance@?$logger_singleton@Umy_logger@@@aux@sources@v2s_mt_nt5@log@boost@@SAXXZ)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "void __cdecl boost::log::v2s_mt_nt5::sources::aux::throw_odr_violation(class boost::typeindex::stl_type_index,class boost::typeindex::stl_type_index,struct boost::log::v2s_mt_nt5::sources::aux::logger_holder_base const &)" (?throw_odr_violation@aux@sources@v2s_mt_nt5@log@boost@@YAXVstl_type_index@typeindex@5@0ABUlogger_holder_base@12345@@Z) referenced in function "public: static void __cdecl boost::log::v2s_mt_nt5::sources::aux::logger_singleton<struct my_logger>::init_instance(void)" (?init_instance@?$logger_singleton@Umy_logger@@@aux@sources@v2s_mt_nt5@log@boost@@SAXXZ)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "unsigned int __cdecl boost::log::v2s_mt_nt5::aux::unhandled_exception_count(void)" (?unhandled_exception_count@aux@v2s_mt_nt5@log@boost@@YAIXZ) referenced in function "public: __thiscall boost::log::v2s_mt_nt5::aux::record_pump<class boost::log::v2s_mt_nt5::sources::severity_logger<int> >::record_pump<class boost::log::v2s_mt_nt5::sources::severity_logger<int> >(class boost::log::v2s_mt_nt5::sources::severity_logger<int> &,class boost::log::v2s_mt_nt5::record &)" (??0?$record_pump@V?$severity_logger@H@sources@v2s_mt_nt5@log@boost@@@aux@v2s_mt_nt5@log@boost@@QAE@AAV?$severity_logger@H@sources@234@AAVrecord@234@@Z)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "class boost::log::v2s_mt_nt5::attribute_name __cdecl boost::log::v2s_mt_nt5::aux::default_attribute_names::severity(void)" (?severity@default_attribute_names@aux@v2s_mt_nt5@log@boost@@YA?AVattribute_name@345@XZ) referenced in function "public: __thiscall boost::log::v2s_mt_nt5::sources::basic_severity_logger<class boost::log::v2s_mt_nt5::sources::basic_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model>,int>::basic_severity_logger<class boost::log::v2s_mt_nt5::sources::basic_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model>,int>(class boost::log::v2s_mt_nt5::sources::basic_severity_logger<class boost::log::v2s_mt_nt5::sources::basic_logger<char,class boost::log::v2s_mt_nt5::sources::severity_logger<int>,struct boost::log::v2s_mt_nt5::sources::single_thread_model>,int> const &)" (??0?$basic_severity_logger@V?$basic_logger@DV?$severity_logger@H@sources@v2s_mt_nt5@log@boost@@Usingle_thread_model@2345@@sources@v2s_mt_nt5@log@boost@@H@sources@v2s_mt_nt5@log@boost@@QAE@ABV01234@@Z)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "unsigned __int64 & __cdecl boost::log::v2s_mt_nt5::sources::aux::get_severity_level(void)" (?get_severity_level@aux@sources@v2s_mt_nt5@log@boost@@YAAA_KXZ) referenced in function "public: virtual class boost::intrusive_ptr<struct boost::log::v2s_mt_nt5::attribute_value::impl> __thiscall boost::log::v2s_mt_nt5::sources::aux::severity_level<int>::impl::detach_from_thread(void)" (?detach_from_thread@impl@?$severity_level@H@aux@sources@v2s_mt_nt5@log@boost@@UAE?AV?$intrusive_ptr@Uimpl@attribute_value@v2s_mt_nt5@log@boost@@@7@XZ)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "public: static struct boost::log::v2s_mt_nt5::aux::stream_provider<char>::stream_compound * __cdecl boost::log::v2s_mt_nt5::aux::stream_provider<char>::allocate_compound(class boost::log::v2s_mt_nt5::record &)" (?allocate_compound@?$stream_provider@D@aux@v2s_mt_nt5@log@boost@@SAPAUstream_compound@12345@AAVrecord@345@@Z) referenced in function "public: __thiscall boost::log::v2s_mt_nt5::aux::record_pump<class boost::log::v2s_mt_nt5::sources::severity_logger<int> >::record_pump<class boost::log::v2s_mt_nt5::sources::severity_logger<int> >(class boost::log::v2s_mt_nt5::sources::severity_logger<int> &,class boost::log::v2s_mt_nt5::record &)" (??0?$record_pump@V?$severity_logger@H@sources@v2s_mt_nt5@log@boost@@@aux@v2s_mt_nt5@log@boost@@QAE@AAV?$severity_logger@H@sources@234@AAVrecord@234@@Z)
1>net_udp_server.obj : error LNK2019: unresolved external symbol "public: static void __cdecl boost::log::v2s_mt_nt5::aux::stream_provider<char>::release_compound(struct boost::log::v2s_mt_nt5::aux::stream_provider<char>::stream_compound *)" (?release_compound@?$stream_provider@D@aux@v2s_mt_nt5@log@boost@@SAXPAUstream_compound@12345@@Z) referenced in function "public: __thiscall boost::log::v2s_mt_nt5::aux::record_pump<class boost::log::v2s_mt_nt5::sources::severity_logger<int> >::auto_release::~auto_release(void)" (??1auto_release@?$record_pump@V?$severity_logger@H@sources@v2s_mt_nt5@log@boost@@@aux@v2s_mt_nt5@log@boost@@QAE@XZ)
1>D:\dev\cpp\server\RakNet\RakNet\Debug\net_udp_server.exe : fatal error LNK1120: 21 unresolved externals
Code Generation -> Runtime Library
установлен наMulti-threaded Debug (/MTd)
? Также может быть полезно добавить разделыC/C++ -> Command Line
иLiner -> Command Line
к вопросу, поскольку в них перечислены все параметры, используемые при компиляции и компоновке. - person dewaffled   schedule 13.08.2016