2 つの GCC コンパイル済み .o オブジェクト ファイルを 3 つ目の .o ファイルに結合するにはどうすればよいですか?
$ gcc -c a.c -o a.o
$ gcc -c b.c -o b.o
$ ??? a.o b.o -o c.o
$ gcc c.o other.o -o executable
ソース ファイルにアクセスできる場合、-combineGCC フラグはコンパイル前にソース ファイルをマージします。
$ gcc -c -combine a.c b.c -o c.o
.oただし、これはソース ファイルに対してのみ機能し、GCC はこのコマンドの入力としてファイルを受け入れません。
通常、.oリンカーの出力を入力として使用できないため、ファイルのリンクは正しく機能しません。結果は共有ライブラリであり、結果の実行可能ファイルに静的にリンクされません。
$ gcc -shared a.o b.o -o c.o
$ gcc c.o other.o -o executable
$ ./executable
./executable: error while loading shared libraries: c.o: cannot open shared object file: No such file or directory
$ file c.o
c.o: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, not stripped
$ file a.o
a.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped