Skip to content

Instantly share code, notes, and snippets.

@hamsham
Created November 3, 2014 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamsham/391ed1f560bbae03a2d0 to your computer and use it in GitHub Desktop.
Save hamsham/391ed1f560bbae03a2d0 to your computer and use it in GitHub Desktop.
/**
* 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