Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's a few errors here:</p> <p><strong>libshared.so is empty</strong></p> <p>Your Makefile doesn't actually link in the shared.o , it just creates an empty shared library. Change </p> <pre><code>g++ -g -ggdb -fPIC -rdynamic -shared -Lstatic -lstatic -o shared/libshared.so </code></pre> <p>to </p> <pre><code>g++ -g -ggdb -fPIC -rdynamic -shared -Lstatic -o shared/libshared.so shared/shared.o -lstatic </code></pre> <p>The -lstatic have to come after shared/shared.o as you have to specify static libraries in reverse order of their dependencies.</p> <p><strong>-fPIC is needed on all object files in a shared library</strong></p> <p>You create a shared library that links in a static library. That static library also have to be compiled with -fPIC, otherwise you're creating a shared library where some parts of it cannot be relocated. Change</p> <pre><code>g++ -g -ggdb -c static/static.cpp -o static/static.o </code></pre> <p>to </p> <pre><code>g++ -fPIC -g -ggdb -c static/static.cpp -o static/static.o </code></pre> <p><strong>C++ symbols get mangled</strong></p> <p>As you're creating a shared library from C++ code, function names and similar gets <a href="http://en.wikipedia.org/wiki/Name_mangling" rel="noreferrer">mangeled</a> This means there is no function name matching the string "function_inside_static_lib" which you try to dynamically load. run nm on the static library, you'll see it's actually named "_Z26function_inside_static_libii" . You can run nm -C to pretty print C++ names.</p> <p>This means your code in app.cpp have to be:</p> <pre><code> function_inside_shared_lib = (int (*)(int, int))dlsym(handle, "_Z26function_inside_static_libii"); </code></pre> <p>This is one of the reasons it's often preferrable to export functions from shared objects using C instead of C++ if you want to dynamically (dlopen) fetch something from a shared library. The C++ name mangling have in the past varied from compiler to compiler, though these days they seem to have all agreed to a standard that won't be changing. With C it's simpler, and the symbols in the shared library will be the same as you gave them in your source code.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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