Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As Martin York pointed out, that's the way it works in Linux. When linking against a library, you have to link to all dependencies, too. That's different in Windows, DLLs take care of their dependencies themselves. When dynamically loading a library that has another library as a dependency, you need to load that library first with the RTLD_GLOBAL flag. This is pretty awkard, imho, since you may not be able to know which dependencies another shared objects requires, or the dependencies can change with a newer version that's otherwise binary compatible. From what I know (and from reading the g++ and ld manpages), it is not possible to create a behaviour similar to Windows' DLLs. Here's a little testcase:</p> <p>two.cpp:</p> <pre><code>#include &lt;iostream&gt; extern "C" { void bar() { std::cout &lt;&lt; "bar()\n"; } } </code></pre> <p>one.cpp:</p> <pre><code>#include &lt;iostream&gt; extern "C" { void bar(); void foo() { std::cout &lt;&lt; "foo()\n"; bar (); } } </code></pre> <p>test.cpp:</p> <pre><code>#include &lt;dlfcn.h&gt; #include &lt;iostream&gt; int main (int argc, char *argv[]) { using namespace std; // void *libtwo = dlopen("./libtwo.so", RTLD_NOW | RTLD_GLOBAL); void *libone = dlopen("./libone.so", RTLD_NOW); if (!libone) { cout &lt;&lt; "dlopen(libone.so) failed: " &lt;&lt; dlerror() &lt;&lt; "\n"; return 1; } typedef void (*foo_t)(); foo_t foo = reinterpret_cast&lt;foo_t&gt;(dlsym(libone, "foo")); if (!foo) { cout &lt;&lt; "dlsym(libone.so, foo) failed\n"; return 2; } } </code></pre> <p>one.cpp is compiled into <code>libone.so</code> and two.cpp in <code>libtwo.so</code>, test.cpp is compiled into the <code>test</code> binary. This will fail and only succeed when the commented line is uncommented.</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