Created
November 3, 2014 04:26
-
-
Save hamsham/391ed1f560bbae03a2d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Testing the plugin interface | |
* If you're using GCC/G++, specify the additional linker options: | |
* | |
* Indicate that this is a shared library: | |
* shared -s | |
* | |
* Use the provided directive to export compiler symbols to the shared library: | |
* -DBUILD_PLUGIN | |
* | |
* Tell the linker to have all exported function symbols use the STDCALL | |
* calling convention for ABI compatibility (use only on Windows). | |
* -Wl,--add-stdcall-alias | |
* | |
* g++ -std=c++11 -Wall -Werror -Wextra -pedantic -pedantic-errors -shared -s -DBUILD_PLUGIN -Wl,--add-stdcall-alias testPlugin.cpp -o testPlugin.dll | |
* | |
* Also, change the compiled output from ".dll" to ".so" on non-windows | |
* targets. | |
*/ | |
#include <iostream> | |
#include "pluginAPI.h" | |
// Derive this class from the plugin base class in pluginAPI.h | |
class pluginTest final : virtual public plugin { | |
// make sure the destructor is marked as virtual. | |
virtual ~pluginTest(); | |
// override the base class method to print data to the console. | |
virtual void printMessage() const override; | |
}; | |
// D-tor | |
pluginTest::~pluginTest() { | |
} | |
// print message | |
void pluginTest::printMessage() const { | |
std::cout << "Hello World!" << std::endl; | |
} | |
// Factory method to instantiate a "pluginTest" class | |
// It is important to do this from within the user-created library due to | |
// differences between compilers. | |
plugin* createPluginInstance() { | |
return new pluginTest; | |
} | |
// Destruction method to destroy an instance of a "pluginTest" obect. | |
// It is important to do this from within the user-created library due to | |
// differences between compilers. | |
void destroyPluginInstance(plugin* const pPlugin) { | |
delete pPlugin; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment