Note that there are some explanatory texts on larger screens.

plurals
  1. POc++ dynamic library dlopen error
    primarykey
    data
    text
    <p>I have two files: RollDice.cpp</p> <pre><code>#include "RollDice.h" #include "./IPlugins.cpp" #include "./IPluginFunctions.cpp" #include &lt;iostream&gt; RollDice::RollDice(IPluginFunctions &amp;iPluginFunctions) : IPlugins(iPluginFunctions) { //srand(time(NULL)); } RollDice::~RollDice() { } void RollDice::callPlugin(std::string paramsText, std::string dataText) { std::cout &lt;&lt; "RollDice ;)\n"; } </code></pre> <p>RollDice.h:</p> <pre><code>#ifndef ROLLDICE_H_ #define ROLLDICE_H_ #include "./IPlugins.h" #include "./IPluginFunctions.h" class RollDice: public IPlugins { public: RollDice(IPluginFunctions &amp;iPluginFunctions); virtual ~RollDice(); virtual void callPlugin(std::string paramsText, std::string dataText); }; extern "C" RollDice* create(IPluginFunctions &amp;iPluginFunctions) { return new RollDice(iPluginFunctions); } extern "C" void destroy(RollDice *rollDice) { delete rollDice; } #endif /* ROLLDICE_H_ */ </code></pre> <p>I create .so file with: g++ -shared -o RollDice.so RollDice.cpp</p> <p>And now in my application I want to open this plugin:</p> <pre><code>this-&gt;plugin = dlopen(directory.c_str(), RTLD_LAZY); if (!(this-&gt;plugin)) { std::cerr &lt;&lt; "Cannot load library: " &lt;&lt; dlerror() &lt;&lt; '\n'; return; } dlerror(); this-&gt;createPlugin = (create_p*) dlsym(plugin, "create"); const char* dlsymError = dlerror(); if (dlsymError) { std::cerr &lt;&lt; "Cannot load symbol create: " &lt;&lt; dlsymError &lt;&lt; '\n'; return; } this-&gt;destroyPlugin = (destroy_p*) dlsym(plugin, "destroy"); dlsymError = dlerror(); if (dlsymError) { std::cerr &lt;&lt; "Cannot load symbol destroy: " &lt;&lt; dlsymError &lt;&lt; '\n'; return; } </code></pre> <p>But I get message: Cannot load library: ./RollDice.so: invalid ELF header</p> <p>Can you help me solving this?</p> <p><code>-fPIC</code> </p> <p>doesn't help</p> <h1>Edit:</h1> <p>Now I'm bulding plugin with:</p> <pre><code>g++ -shared -fPIC -o RollDice.so RollDice.h IPlugins.cpp IPluginFunctions.cpp </code></pre> <p>and I have new problem: Cannot load symbol create: ./RollDice.so: undefined symbol: create</p> <p>When I use <code>nm</code> to see what symbols are in RollDice.so I don't see "create"</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload