Note that there are some explanatory texts on larger screens.

plurals
  1. POconstraints when dynamically loading a shared object from another shared object?
    text
    copied!<p>I'm dynamically loading (whith <code>dlopen()</code>) a shared object (named <code>libprofile1.so</code>) from <code>main</code>. </p> <p>In <code>libprofile1.so</code> I have defined factory function <code>CreateProfile</code> and class <code>Profile</code>. <code>CreateProfile</code> function creates an instance of <code>Profile</code> class and returns a pointer to it. Class <code>Profile</code> has a method <code>pMethod</code>. </p> <p>In main, after loading <code>libprofile1.so</code>, I'm calling <code>CreateProfile</code> method which returns the pointer to the object of <code>Profile</code> class (call it <code>p</code>).<br> Afterwards, I'm calling <code>pMethod</code> method against object <code>p</code> (<code>p-&gt;pMethod</code>). In this method I'm dynamically loading other shared object (<code>libdatasources.so</code>). </p> <p>In this shared object I have a factory function <code>CreateDataSource</code>and class <code>DataSource</code>.<br> <code>CreateDataSource</code> function creates an instance of <code>DataSource</code> class and returns a pointer to it. <code>DataSource</code> class has method <code>dsMethod</code>. </p> <p>As you can notice, structures of both shared objects are similar.</p> <p>From <code>pMethod</code> after loading <code>libdatasources.so</code> I'm calling <code>CreateDataSource</code> method, which returns me a pointer to an instance of <code>DataSource</code> class, call it <code>ds</code>. Then I'm calling <code>dsMethod</code> of <code>ds</code> object<br> (<code>ds-&gt;dsMethod</code>).</p> <hr> <p>Now, the problem is following. </p> <p>When I try to call <code>dsMethod</code> of <code>ds</code> object, shared object that I'm first loading (<code>libprofile1.so</code>) doesn't load. Actually <code>dlopen()</code> returns <code>NULL</code>. When I read <code>dlerror</code> after <code>dlopen</code> I get:</p> <p><code>./libprofile1.so: undefined symbol: _ZN18DataSource13dsMethod</code></p> <p>So if I have a call <code>ds-&gt;Method</code>, than first shared object doesn't load!<br> If I comment out call <code>ds-&gt;dsMethod</code> from the source, then my <code>libprofile1.so</code> and <code>libdatasources.so</code> are loaded without any problems.<br> I don't see the connection between the call of a method from the second SO, with loading first SO???</p> <p>Maybe I don't know, but are there any constraints when dynamically loading a shared object, from a shared object that's also been dynamically loaded?</p> <p>Btw, <code>dlopen</code> is used with <code>RTLD_NOW|RTLD_GLOBAL</code>. I tried with <code>RTLD_LAZY</code>, but still the same problem.</p> <p><strong>UPDATE:</strong></p> <p>Libraries are built in Eclipse. Options for G++ compiler and linker are the same for both libraries.<br> Here are G++ compiler:</p> <pre><code>-O0 -g3 -Wall -c -fmessage-length=0 </code></pre> <p>and G++ linker:</p> <pre><code>-shared </code></pre> <p>options, pasted from <code>Project Properties -&gt; Settings -&gt; Tool Settings</code></p> <p>Thanks in advance.</p>
 

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