1 #ifndef RuntimeLibrary_HH
2 #define RuntimeLibrary_HH
19 std::string _result, std::string _what);
25 void print(std::ostream &sout)
const;
31 std::string _result, std::string _what);
37 void print(std::ostream &sout)
const;
46 RuntimeLibrary(std::string _filename_base, std::string _compile_options,
47 std::string _so_options);
57 template <
typename Signature>
58 std::function<Signature>
get_function(std::string function_name)
const {
59 std::function<Signature> func =
60 reinterpret_cast<Signature *
>(dlsym(
m_handle, function_name.c_str()));
62 const char *dlsym_error = dlerror();
64 throw std::runtime_error(std::string(
65 "Cannot load symbol " + function_name +
" \n" + dlsym_error));
81 static std::pair<std::string, std::string>
default_cxx();
Write, compile, load and use code at runtime.
std::string m_compile_options
static std::pair< std::string, std::string > default_soflags()
Default c++ compiler options.
static std::pair< fs::path, std::string > default_boost_includedir()
Return default includedir for boost.
static std::pair< std::string, std::string > default_cxxflags()
Default c++ compiler options.
void _close()
Close the current library.
RuntimeLibrary(std::string _filename_base, std::string _compile_options, std::string _so_options)
Construct a RuntimeLibrary object, with the options to be used for compile the '.o' file and the '....
static std::pair< fs::path, std::string > default_casm_includedir()
Return default includedir for CASM.
static std::pair< fs::path, std::string > default_boost_libdir()
Return default libdir for boost.
void rm()
Remove the current library and source code.
static std::pair< std::string, std::string > default_cxx()
Return default compiler.
void _load()
Load a library with a given name.
std::function< Signature > get_function(std::string function_name) const
Obtain a function from the current library.
void _compile()
Compile a shared library.
static std::pair< fs::path, std::string > default_casm_libdir()
Return default libdir for CASM.
std::string m_filename_base
std::string filename_base
void print(std::ostream &sout) const
runtime_lib_compile_error(std::string _filename_base, std::string _cmd, std::string _result, std::string _what)
void print(std::ostream &sout) const
runtime_lib_shared_error(std::string _filename_base, std::string _cmd, std::string _result, std::string _what)
std::string filename_base
std::string include_path(const fs::path &dir)
std::string link_path(const fs::path &dir)
DirectoryStructure const & dir