In C it would be like: $ gcc hello.c -o hello.o -c hello.c: In function ‘main’: hello.c:3:1: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default] printf("hello world!\n"); ^ $ file hello.o hello.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped $ gcc hello.o -r /usr/bin/ld: cannot find -lgcc_s /usr/bin/ld: cannot find -lc /usr/bin/ld: cannot find -lgcc_s collect2: error: ld returned 1 exit status But the actual problem user experienced was: $ gfortran -v -r -o BIG.o a.o b.o c.o ... Driving: gfortran -v -r -o BIG.o a.o b.o c.o -l gfortran -l m -shared-libgcc ... OLLECT_GCC_OPTIONS='-v' '-r' '-o' 'BIG.o' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /usr/libexec/gcc/x86_64-redhat-linux/8/collect2 -plugin /usr/libexec/gcc/x86_64-redhat-linux/8/liblto_plugin.so -plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper -plugin-opt=-fresolution=/tmp/ccEsZ4ao.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lquadmath -plugin-opt=-pass-through=-lm -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o BIG.o -r /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/8/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/8 -L/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/8/../../.. a.o b.o c.o ... -lgfortran -lm -lgcc_s -lgcc -lquadmath -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-redhat-linux/8/crtend.o /usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crtn.o /usr/bin/ld: cannot find -lgfortran /usr/bin/ld: cannot find -lm /usr/bin/ld: cannot find -lgcc_s /usr/bin/ld: cannot find -lquadmath /usr/bin/ld: cannot find -lm /usr/bin/ld: cannot find -lgcc_s /usr/bin/ld: cannot find -lc /usr/bin/ld: cannot find -lgcc_s collect2: error: ld returned 1 exit status The driver should print some error message when '-r' is used like this. As well as some explanation about the issue. The linker is attempting to statically link.
It seems to me that the problem is rather that in older GCCs -r didn't imply -nostdlib. So I think the workaround/solution is to use -r -nostdlib.