Last active
March 24, 2017 22:28
-
-
Save sehe/587707da5bee957eb806789a248b1e76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "a.h" | |
#include <boost/asio/error.hpp> | |
#include <iostream> | |
#include <map> | |
#include <sstream> | |
namespace A { | |
std::string ErrorCodeToString(const boost::system::error_code & errorCode) | |
{ | |
static const std::map<boost::system::error_code, std::string> my_own_descriptions { | |
{ boost::asio::error::eof, "Server has disconnected." }, | |
{ boost::asio::error::connection_refused, "Connection Refused." }, | |
}; | |
auto& c = errorCode.category(); | |
std::cout << "Match get_misc_category(): " << (c == boost::asio::error::get_misc_category()) | |
<< " misc_category(): " << (c == boost::asio::error::misc_category) << "\n"; | |
std::ostringstream debugMsg; | |
debugMsg << "Error Category: " << errorCode.category().name() << ". " | |
<< "Error Message: " << errorCode.message() << ". "; | |
auto match = my_own_descriptions.find(errorCode); | |
if (match != my_own_descriptions.end()) { | |
debugMsg << "Server has disconnected."; | |
} | |
else { | |
debugMsg << "Unknown Error."; | |
} | |
return debugMsg.str(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <boost/system/error_code.hpp> | |
#include <string> | |
namespace A { | |
std::string ErrorCodeToString(const boost::system::error_code & errorCode); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "b.h" | |
#include <boost/asio/error.hpp> | |
namespace B { | |
boost::system::error_code foo() { | |
return boost::asio::error::eof; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <boost/system/error_code.hpp> | |
namespace B { | |
boost::system::error_code foo(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define BOOST_ERROR_CODE_HEADER_ONLY | |
#include <boost/asio/error.hpp> | |
// just to define the globals that would normally be in the dynamic library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ | |
-isystem /home/sehe/custom/boost \ | |
-std=c++11 \ | |
-g -O2 -pthread -march=native") | |
add_definitions("-DBOOST_SYSTEM_NO_LIB") | |
ADD_LIBRARY(a_a a.cpp) | |
ADD_LIBRARY(b_a b.cpp) | |
ADD_LIBRARY(c_a c.cpp) | |
ADD_EXECUTABLE(sotest test.cpp) | |
target_link_libraries(a_a c_a) | |
target_link_libraries(b_a c_a) | |
target_link_libraries(sotest a_a b_a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "a.h" // one static library, static linked to boost system | |
#include "b.h" // another static library, static linked to boost system | |
#include <iostream> | |
int main() { | |
std::cout << A::ErrorCodeToString(B::foo()) << "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment