Postgresql libecpg-dev パッケージの次のライブラリを必要とする C プログラムの静的実行可能ファイルをビルドしようとしています: libecpg、libpq、および libpgtypes。静的ライブラリ libecpg.a、libpq.a、libpgtypes.a はすべて、動的バージョン /usr/lib と同じ場所にあります。とにかく -L オプションをパスとして追加しようとしましたが、同じ結果が得られます。
ユーザーがライブラリをシステムにインストールして使用する必要がないように、バイナリを移植できるように、実行可能ファイルを静的にする必要があります。動的ライブラリで次のコマンドを使用すると、プログラムは正常にビルドされます: (使用している一部の Postgresql 関数には -I ディレクトリを含める必要があります)
gcc main.o -lecpg -lpq -lpgtypes -I/usr/include/postgresql -o program_name
静的ライブラリにリンクしようとすると、次のコマンドを使用しています。
gcc -static main.o -lecpg -lpq -lpgtypes -I/usr/include/postgresql -o program_name
ただし、コンパイラは、「未定義の参照」エラーの長いリストを出力として提供します。たくさんありますが、ここに小さなサンプルがあります:
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libecpg.a(descriptor.o):
In function `get_descriptors':
(.text+0xc3): undefined reference to `pthread_once'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libecpg.a(descriptor.o): In function `ECPGdeallocate_desc':
(.text+0x2c6): undefined reference to `pthread_setspecific'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libecpg.a(descriptor.o): In function `ECPGallocate_desc':
(.text+0x376): undefined reference to `pthread_setspecific'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libecpg.a(descriptor.o): In function `get_descriptors':
(.text+0xd2): undefined reference to `pthread_getspecific'
次のように順序を変更すると:
gcc -I/usr/include/postgresql -static -lecpg -lpq -lpgtypes -o program_name main.o
代わりに、コンパイラの出力は次のようになります (これもほんの一部のサンプルです)。
main.c:(.text+0x5c6): undefined reference to `ECPGconnect'
main.c:(.text+0x83e): undefined reference to `ECPGdo'
main.c:(.text+0x843): undefined reference to `ECPGget_sqlca'
main.c:(.text+0x85c): undefined reference to `ECPGdisconnect'
main.c:(.text+0x87c): undefined reference to `ECPGget_sqlca'
-I オプションを (他のすべてのオプションと共に) あらゆる場所で使用しようとしましたが、何も機能しないようです。