What is the relationship between gcc linking and ld linking?

He said that the linux loader is / usr / bin / ld, but we usually use gcc / g ++ to link libraries and executables, we barely use "ld".

The last time I used "ld" manually, when I studied the linux build, the only way to generate an executable file is to use the ld.o file to generate the executable directly without any library.

My question is that gcc / g ++ contains some function wrappers from "ld" because raw "ld" is too hard to use? Or should we never use "ld" explicitly for linking c / C ++ programs because of blablabla?

Many thanks.

+4
source share
3 answers

gcc provides several default options for ld.

ldknows nothing about C ++ or any other language. ldI have no idea what libraries your code should work with. If you try to directly link your compiled C ++ code with ld, it will help you, as it ldalone does not know where it can find the runtime library libstdc++, gcc C ++. Do you use strings? vectors? Most of them are template code that compiles as part of your object module. But there are a few more pre-compiled bits in libstdc++which you need to associate.

gcc , gcc , ld, ld, , , .

ld, , , , gcc. ? gcc gcc-compiled c ode.

+6

, gcc/g++ "ld"

.

raw-ld ?

, ; , , .

, (, libstd++. a) , ( ).

"ld" c/++ - blablabla?

, . , , - , . ld, g++ - , !

+2

ld ++, , ++. g++ , , libstdc++.a. ld , "" .

+2

Source: https://habr.com/ru/post/1665184/


All Articles