私はCreating Library with backward compatible ABI that uses Boostのスレッドを読んでいますが、安定したABIを維持するために共有ライブラリをどのようにリンクするべきかを理解しようとしています。共有ライブラリとLinux(elf)のリンク
cat <<EOF > a.c
#define ABI __attribute__((visibility("default")))
int common();
int ABI a() { return common() + 1; }
EOF
cat <<EOF > b.c
#define ABI __attribute__((visibility("default")))
int common();
int ABI b() { return common() + 2; }
EOF
cat <<EOF > common_v1.c
int common() { return 1; }
EOF
cat <<EOF > common_v2.c
int common() { return 2; }
EOF
cat <<EOF > test.c
#include <assert.h>
int a();
int b();
int main(int argc, const char *argv[])
{
assert(a() + b() == 6);
return 0;
}
EOF
cat <<EOF > 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
は、ライブラリがcommon_v1とcommon_v2は、ライブラリと(ブーストなど)Bの外部依存関係をエミュレートする必要があります。
私は、次の簡単なテストプロジェクトを作成しました。 common_v1とcommon_v2は外部ライブラリとみなされるので、私はビルドシステムを変更したくないです(コンパイルされたフラグは変更しないでください)。
上記のプロジェクトはうまくコンパイルされますが、機能しません。テストアプリケーションが実行されると、テストアプリケーションはassertステートメントにジャンプします。
私は、共通の定義がlibaとlibbの両方で使用されていると考えています。なぜこれが当てはまり、私は何が間違っているのですか?