Note that there are some explanatory texts on larger screens.

plurals
  1. POShared libraries and linking on Linux (elf)
    primarykey
    data
    text
    <p>I have read the thread on <a href="https://stackoverflow.com/questions/836875/creating-library-with-backward-compatible-abi-that-uses-boost">Creating Library with backward compatible ABI that uses Boost</a> and I'm now trying to understand how I should link my shared libraries to maintain a stable ABI, and avoid problems with interfering symbols.</p> <p>I have created the following simple test project:</p> <pre><code>cat &lt;&lt;EOF &gt; a.c #define ABI __attribute__((visibility("default"))) int common(); int ABI a() { return common() + 1; } EOF cat &lt;&lt;EOF &gt; b.c #define ABI __attribute__((visibility("default"))) int common(); int ABI b() { return common() + 2; } EOF cat &lt;&lt;EOF &gt; common_v1.c int common() { return 1; } EOF cat &lt;&lt;EOF &gt; common_v2.c int common() { return 2; } EOF cat &lt;&lt;EOF &gt; test.c #include &lt;assert.h&gt; int a(); int b(); int main(int argc, const char *argv[]) { assert( a() + b() == 6 ); return 0; } EOF cat &lt;&lt;EOF &gt; CMakeLists.txt cmake_minimum_required(VERSION 2.8) project(TEST) add_library(common_v1 STATIC common_v1.c) add_library(common_v2 STATIC common_v2.c) SET_SOURCE_FILES_PROPERTIES( a.c b.c COMPILE_FLAGS -fvisibility=hidden ) add_library(a SHARED a.c) target_link_libraries(a common_v1) add_library(b SHARED b.c) target_link_libraries(b common_v2) add_executable(test test.c) target_link_libraries(test a b) EOF </code></pre> <p>The libraries common_v1 and common_v2 should emulate an external dependency of the libraries a and b (like Boost). Because common_v1 and common_v2 is considered as external libraries, I would prefer not to change their build system (and there by not change the flags they are compiled with).</p> <p>The project above, compiles fine, but it does not work! When the test application is executed it jumps into the assert statement.</p> <p>This makes me believe the same definition of common is used in both liba and libb. Why is this the case, and what am I doing wrong?</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.
    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