2016-05-03 16:20:42 +03:00
|
|
|
#include <kwsys/DynamicLoader.hxx>
|
|
|
|
|
2007-04-17 21:43:03 +04:00
|
|
|
#include <example.h>
|
|
|
|
|
2007-04-17 21:52:50 +04:00
|
|
|
#include <example_exe.h>
|
|
|
|
|
2015-08-28 22:07:00 +03:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
2007-04-17 21:43:03 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
// Implement the ABI used by plugins.
|
|
|
|
extern "C" int example_exe_function()
|
|
|
|
{
|
2015-08-28 22:07:00 +03:00
|
|
|
std::cout << "hello" << std::endl;
|
2007-04-17 21:43:03 +04:00
|
|
|
return 123;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CMAKE_INTDIR
|
2016-05-16 17:34:04 +03:00
|
|
|
#define CONFIG_DIR "/" CMAKE_INTDIR
|
2007-04-17 21:43:03 +04:00
|
|
|
#else
|
2016-05-16 17:34:04 +03:00
|
|
|
#define CONFIG_DIR ""
|
2007-04-17 21:43:03 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2015-08-28 22:07:00 +03:00
|
|
|
std::string libName = EXAMPLE_EXE_PLUGIN_DIR CONFIG_DIR "/";
|
2007-04-17 21:43:03 +04:00
|
|
|
libName += kwsys::DynamicLoader::LibPrefix();
|
|
|
|
libName += "example_mod_1";
|
|
|
|
libName += kwsys::DynamicLoader::LibExtension();
|
|
|
|
kwsys::DynamicLoader::LibraryHandle handle =
|
|
|
|
kwsys::DynamicLoader::OpenLibrary(libName.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!handle) {
|
2016-06-07 00:53:32 +03:00
|
|
|
std::cerr << "Could not open plugin \"" << libName << "\"!" << std::endl;
|
2007-04-17 21:43:03 +04:00
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-04-17 21:43:03 +04:00
|
|
|
kwsys::DynamicLoader::SymbolPointer sym =
|
|
|
|
kwsys::DynamicLoader::GetSymbolAddress(handle, "example_mod_1_function");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!sym) {
|
|
|
|
std::cerr << "Could not get plugin symbol \"example_mod_1_function\"!"
|
|
|
|
<< std::endl;
|
2007-04-17 21:43:03 +04:00
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-04-19 19:32:43 +04:00
|
|
|
#ifdef __WATCOMC__
|
2016-05-16 17:34:04 +03:00
|
|
|
int(__cdecl * f)(int) = (int(__cdecl*)(int))(sym);
|
2007-04-19 19:32:43 +04:00
|
|
|
#else
|
2016-05-16 17:34:04 +03:00
|
|
|
int (*f)(int) = reinterpret_cast<int (*)(int)>(sym);
|
2007-04-19 19:32:43 +04:00
|
|
|
#endif
|
2016-05-16 17:34:04 +03:00
|
|
|
if (f(456) != (123 + 456)) {
|
|
|
|
std::cerr << "Incorrect return value from plugin!" << std::endl;
|
2007-04-17 21:43:03 +04:00
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2007-09-11 01:10:40 +04:00
|
|
|
kwsys::DynamicLoader::CloseLibrary(handle);
|
2007-04-17 21:43:03 +04:00
|
|
|
return 0;
|
|
|
|
}
|