さらに調査した後、私はそれらがどのように機能するかを理解しました。共有ライブラリの未定義のシンボルを操作するための2つのリンカーオプションがあります。
最初のものは--no-undefined
です。リンク段階で、すぐに解決されない未解決のシンボルを報告します。手動(-l
スイッチを使用)または自動(libgcc_s
、C ++ランタイム; libc
、Cランタイム; ld-linux-**.so
、動的リンカーutils)でリンクされた共有ライブラリでシンボルが見つからない限り、--no-undefined
エラーとして報告されます。それが質問者が必要とした鍵です。
別のキーがあります--no-allow-shlib-undefined
(その説明も示唆してい--no-undefined
ます)。共有ライブラリをリンクする共有ライブラリの定義が満たされているかどうかを確認します。このトピックに示されているケースでは、このキーはほとんど役に立ちませんが、役立つ場合があります。ただし、それ自体に障害があります。
マンページは、それがデフォルトではない理由についてのいくつかの理論的根拠を提供します。
--allow-shlib-undefined
--no-allow-shlib-undefined
Allows (the default) or disallows undefined symbols in shared
libraries (It is meant, in shared libraries _linked_against_, not the
one we're creating!--Pavel Shved). This switch is similar to --no-un-
defined except that it determines the behaviour when the undefined
symbols are in a shared library rather than a regular object file. It
does not affect how undefined symbols in regular object files are
handled.
The reason that --allow-shlib-undefined is the default is that the
shared library being specified at link time may not be the same as
the one that is available at load time, so the symbols might actually
be resolvable at load time. Plus there are some systems, (eg BeOS)
where undefined symbols in shared libraries is normal. (The kernel
patches them at load time to select which function is most appropri-
ate for the current architecture. This is used for example to dynam-
ically select an appropriate memset function). Apparently it is also
normal for HPPA shared libraries to have undefined symbols.
ld-linux.so
たとえば、共有ライブラリの内部ルーチンの一部が動的ローダー(実行可能ファイルと共有ライブラリの両方)に実装されているLinuxシステムの場合、上記の内容も当てはまります。どういうわけかそれをリンクしない限り、あなたはこのようなものを得るでしょう:
/lib64/libc.so.6: undefined reference to `_dl_argv@GLIBC_PRIVATE'
/lib64/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'
/usr/lib64/gcc/x86_64-suse-linux/4.3/libstdc++.so: undefined reference to `__tls_get_addr@GLIBC_2.3'
/lib64/libc.so.6: undefined reference to `_rtld_global@GLIBC_PRIVATE'
/lib64/libc.so.6: undefined reference to `__libc_enable_secure@GLIBC_PRIVATE'
これらは、ローダーからの未定義の参照ld-linux.so
です。これはプラットフォーム固有です(たとえば、私のシステムでは正しいローダーはです/lib64/ld-linux-x86-64.so
)。ローダーをライブラリにリンクして、上記のトリッキーな参照も確認できます。
g++ -fPIC -shared -o liba.so a.o -Wl,--no-allow-shlib-undefined /lib64/ld-linux-x86-64.so.2