diff --git a/CMakeLists.txt b/CMakeLists.txt index e69e7b59..dc9d559e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.2) project(HPCore) -add_definitions("-std=c++17") +add_definitions("-std=c++17" "-fno-exceptions") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build) @@ -22,7 +22,7 @@ add_executable(hpcore target_link_libraries(hpcore libsodium.a libboost_system.a - libboost_filesystem.a + stdc++fs pthread protobuf.a ) \ No newline at end of file diff --git a/src/conf.cpp b/src/conf.cpp index 7ffd85c9..edd62319 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -1,13 +1,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include "conf.hpp" #include "crypto.hpp" #include "util.hpp" @@ -67,15 +67,15 @@ int rekey() */ int create_contract() { - if (boost::filesystem::exists(ctx.contractDir)) + if (std::experimental::filesystem::exists(ctx.contractDir)) { std::cerr << "Contract dir already exists. Cannot create contract at the same location.\n"; return -1; } - boost::filesystem::create_directories(ctx.configDir); - boost::filesystem::create_directories(ctx.histDir); - boost::filesystem::create_directories(ctx.stateDir); + std::experimental::filesystem::create_directories(ctx.configDir); + std::experimental::filesystem::create_directories(ctx.histDir); + std::experimental::filesystem::create_directories(ctx.stateDir); //Create config file with default settings. @@ -335,7 +335,7 @@ int validate_config() } // Check whether the contract binary actually exists. - if (!boost::filesystem::exists(cfg.binary)) + if (!std::experimental::filesystem::exists(cfg.binary)) { std::cerr << "Contract binary does not exist: " << cfg.binary << std::endl; return -1; @@ -364,7 +364,7 @@ int validate_contract_dir_paths() for (std::string &dir : dirs) { - if (!boost::filesystem::exists(dir)) + if (!std::experimental::filesystem::exists(dir)) { std::cerr << dir << " does not exist.\n"; return -1; diff --git a/src/main.cpp b/src/main.cpp index efd4f55e..c29b1ccd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,9 @@ Entry point for HP Core **/ +// This will direct all boost exceptions to our error handler. +#define BOOST_NO_EXCEPTIONS + #include #include #include @@ -147,3 +150,12 @@ int main(int argc, char **argv) std::cout << "exited normally\n"; return 0; } + +/** + * Global exception handler for boost exceptions. + */ +void boost::throw_exception(std::exception const &e) +{ + std::cerr << "Boost error:" << e.what() << std::endl; + exit(-1); +} \ No newline at end of file