2

Why does the following code output "Unknown error"? I expect some other message like "operation timed out" or other descriptive error.

OS: Windows 7 boost: 1.57

#include <iostream>
#include "boost/system/system_error.hpp"

void main()
{
    boost::system::error_code ec = make_error_code(boost::system::errc::timed_out);
    auto message = ec.message();
    std::cout << message << std::endl;
}
klmurphy72
  • 21
  • 4

1 Answers1

0

Suggest you check include paths, library paths and project settings.

I have corrected the program (main must return an int) and compiled under clang:

#include <iostream>
#include <boost/system/system_error.hpp>

int main()
{
    boost::system::error_code ec = make_error_code(boost::system::errc::timed_out);
    auto message = ec.message();
    std::cout << message << std::endl;
}

command line:

c++ -std=c++14 -I${HOME}/local/include -L${HOME}/local/lib -lboost_system

result:

Operation timed out

My boost installation is installed to the prefix ${HOME}/local

Richard Hodges
  • 68,278
  • 7
  • 90
  • 142
  • I think this may be a Windows thing. – klmurphy72 Apr 25 '16 at 23:20
  • @klmurphy72 have you tried assigning the error to an error_condition rather than an error_code? – Richard Hodges Apr 25 '16 at 23:22
  • I changed from error_code to error_condition and the result is the same. This seems correct to me as the error value and the category remained unchanged. At least that is how I understand it. Either method ends up in "generic_error_category::message(int ev)". – klmurphy72 Apr 25 '16 at 23:30