Debian Codegraph @

Tests/Plugin/src/example_exe.cxx

raw symbols SCIP
1 #include <iostream>
2 #include <string>
3
4 #include <example.h>
5 #include <example_exe.h>
6 #include <stdio.h>
7
8 #include "DynamicLoader.hxx"
9
10 // Implement the ABI used by plugins.
11 extern "C" int example_exe_function()
12 {
13 std::cout << "hello" << std::endl;
14 return 123;
15 }
16
17 #ifdef CMAKE_INTDIR
18 # define CONFIG_DIR "/" CMAKE_INTDIR
19 #else
20 # define CONFIG_DIR ""
21 #endif
22
23 int main()
24 {
25 std::string const libName = EXAMPLE_EXE_PLUGIN_DIR CONFIG_DIR
26 "/" EXAMPLE_EXE_MOD_PREFIX "example_mod_1" EXAMPLE_EXE_MOD_SUFFIX;
27 DynamicLoader::LibraryHandle handle = DynamicLoader::OpenLibrary(libName);
28 if (!handle) {
29 // Leave the .c_str() on this one. It is needed on OpenWatcom.
30 std::cerr << "Could not open plugin \"" << libName.c_str() << "\"!"
31 << std::endl;
32 return 1;
33 }
34 DynamicLoader::SymbolPointer sym =
35 DynamicLoader::GetSymbolAddress(handle, "example_mod_1_function");
36 if (!sym) {
37 std::cerr << "Could not get plugin symbol \"example_mod_1_function\"!"
38 << std::endl;
39 return 1;
40 }
41 #ifdef __WATCOMC__
42 int(__cdecl * f)(int) = (int(__cdecl*)(int))(sym);
43 #else
44 int (*f)(int) = reinterpret_cast<int (*)(int)>(sym);
45 #endif
46 if (f(456) != (123 + 456)) {
47 std::cerr << "Incorrect return value from plugin!" << std::endl;
48 return 1;
49 }
50 DynamicLoader::CloseLibrary(handle);
51 return 0;
52 }