简体   繁体   English

g ++既是c ++编译器又是链接器?

[英]Is g++ both a c++ compiler and a linker?

I was looking at the output from my build in Eclipse. 我正在查看Eclipse中构建的输出。 I'm cross compiling for a ColdFire processor. 我正在为ColdFire处理器进行交叉编译。 The compilation line looks like this: 编译行看起来像这样:

m68k-elf-g++ -O2 -falign-functions=4 -IC:\nburn\include -IC:\nburn\MOD52...

followed by more include file, obvious "compiler" flags and finally the one source file I changed. 接着是更多的包含文件,明显的“编译器”标志,最后是我改变的一个源文件。 The next line invokes the same tool again: 下一行再次调用相同的工具:

m68k-elf-g++ src\main.o src\TouchPanelMediator.o src\Startup.o....

followed by more .o files some .ld files and some .a files. 接着是更多的.o文件,一些.ld文件和一些.a文件。 This appears to be linking all the various types of object files together. 这似乎是将所有各种类型的目标文件链接在一起。

In the Gnu family is g++ some uber application that can determine based on arguments whether it needs to compile or link? 在Gnu家族中,g ++是一些超级应用程序,可以根据参数确定是否需要编译或链接? Does it have both capabilities built-in or is it just dispatching compiling to gcc and linking to ld and my log just doesn't show that? 它是否具有内置的功能,或者它只是调度编译到gcc并链接到ld而我的日志只是没有显示?

g++ and gcc are drivers . g++gcc驱动程序 Usually, they run the preprocessor ( cpp ), compiler proper ( cc1plus for C++ and cc1 for C) and the linker (gold or GNU ld) and all other things necessary. 通常,它们运行预处理器( cpp ),适当的编译器(用于C ++的cc1plus和用于C的cc1 )和链接器(gold或GNU ld)以及所有其他必要的东西。 The difference between gcc and g++ is that the latter includes one additional library to link against ( libstdc++ ). gccg++之间的区别在于后者包含一个要链接的附加库( libstdc++ )。

Depending on what type of file they are invoked on, they may omit some steps or do things differently. 根据调用它们的文件类型,它们可能会省略某些步骤或以不同方式执行操作。 For .o files, it doesn't need to run the compiler proper or the preprocessor, for example. 例如,对于.o文件,它不需要运行正确的编译器或预处理器。

If you pass -### to them, you can see it print the tools it invokes in each step of its execution. 如果你将-###传递给它们,你可以看到它在它执行的每一步中打印它调用的工具。

Taken from this little GCC guide : 取自这个小GCC指南

Based on the file extension that you gave your program, it selects the appropriate commands it needs to run to turn the source you gave it into the output file you specified. 根据您为程序提供的文件扩展名,它会选择运行所需的相应命令,以将您提供的源转换为您指定的输出文件。

With a nice little flowchart of what GCC exactly does, depending on the file extensions: 有一个很好的GCC精确的流程图,取决于文件扩展名:

input extensions      runs     if   output  

GCC运行流程

It dispatches linking to ld. 它调度链接到ld。

Also see here: How to get GCC linker command? 另请参见: 如何获取GCC链接器命令?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM