From 08dd279787176f673fe4739e7965450644fbb41a Mon Sep 17 00:00:00 2001 From: retf Date: Tue, 12 Aug 2014 10:34:06 -0300 Subject: [PATCH] load_self example --- example/Jamfile.v2 | 4 ++++ example/load_self.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 example/load_self.cpp diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index 0adc5a4..bacf2b7 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -37,3 +37,7 @@ exe shared_library_load_plugin exe getting_started : getting_started.cpp ; + +exe load_self + : load_self.cpp + ; diff --git a/example/load_self.cpp b/example/load_self.cpp new file mode 100644 index 0000000..dddcf8d --- /dev/null +++ b/example/load_self.cpp @@ -0,0 +1,33 @@ +// Copyright 2011-2012 Renato Tegon Forti. +// Copyright 2014 Renato Tegon Forti, Antony Polukhin. +// 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) + +// For more information, see http://www.boost.org + +// ------------------------------------------------------------------------------------- +// This example shows how to use load_self to load symbols direct on executable +// ------------------------------------------------------------------------------------- + +#include +#include + +extern "C" BOOST_SYMBOL_EXPORT int sumexe(int x, int y) +{ + return x+y; +} + +int main(int argc, char* argv[]) { + std::cout << "Application started" << std::endl; + + boost::plugin::shared_library self; + self.load_self(); + + if(self.search_symbol("f")) + { + boost::function sum = self.get("sumexe"); + std::cout << "Computed Value: " << sum(2,2) << std::endl; + } +} +