I want to know when I should use ld linker instead off gcc.
I just wrote a simply hello world in c++, of course I include iostream library. If I want make a binary file with gcc, I just use: g++ hello hello.cpp and I've got my binary file.
Later I try to use ld linker. To get object file I use:
g++ -c hello.cpp. OK that was easy, but the link command was horrible long:
ld -o hello.out hello.o \
-L /usr/lib/gcc/x86_64-linux-gnu/4.8.4/ \
/usr/lib/gcc/x86_64-linux-gnu/4.8.4/crtbegin.o \
/usr/lib/gcc/x86_64-linux-gnu/4.8.4/crtend.o \
/usr/lib/x86_64-linux-gnu/crti.o \
/usr/lib/x86_64-linux-gnu/crtn.o \
/usr/lib/x86_64-linux-gnu/crt1.o \
-dynamic-linker /lib64/ld-linux-x86-64.so.2 -lstdc++ -lc
I know fact that gcc uses the ld.
Using gcc is better in all cases or just in most cases? Please, tell me something about cases where ld linker has advantage.
gccorg++is going to save you a lot of typing and more importantly all the grief involved in figuring out exactly what you need to type and when.gcc -o hello hello.o.