gcc - 为什么 Go 源码包含很多 .go 文件?它们是如何编译的?

标签 gcc go compilation compiler-construction cross-compiling

我想知道 go 编译器是如何工作的!

https://github.com/golang/go 此源包含 88% 的 .go 文件。

所以这应该有另一个编译器来执行 .go 文件。

示例:https://github.com/golang/go/blob/964639cc338db650ccadeafb7424bc8ebb2c0f6c/src/go/ast/ast.go

Golang 使用什么编译器来生成最终的执行文件?!他们从哪里获得资源?

可能是 Golang 生成了一个 c 代码,然后使用 GCC 或 ...?

新更新

我不想要 go1.4 然后在使用 c。

github.com/golang/go 的 88% 来源是 .go 文件。什么编译 .go Go Source 文件?我想看看 Final GO 编译器?

https://github.com/golang/go/search?l=c

我认为这叫做 cg


意思是一个旧版本的 Go 编译器(1.4 版)被用来编译新版本的 Go 编译器。???!

go-go1.4.3/src/go/token/token.go 这是 go token,lexer,写在 GO 上

功能:“功能”, 走:“走”, Go:“转到”, 如果如果”, 进口:“进口”,

那么主编译器在哪里执行.go文件?

go-go1.4.3/src/runtime/compiler.go

// Copyright 2012 The Go Authors.  All rights reserved.
package runtime
// Compiler is the name of the compiler toolchain that built the
// running binary.  Known toolchains are:
//
//  gc      The 5g/6g/8g compiler suite at code.google.com/p/go.
//  gccgo   The gccgo front end, part of the GCC compiler suite.
//
const Compiler = "gc"

go-go1.4.3/src/cmd/gc$ 制作

go tool dist install -v
make: go: Command not found
../../Make.dist:13: recipe for target 'install' failed
make: *** [install] Error 127

make gc 为什么需要 Go?!


上一版GO Language怎么用?!意思是这如何为跨平台生成输出?这使用生成代码到 C,然后使用 c 编译器?

最佳答案

根据 https://golang.org/doc/go1.5#implementationhttps://www.infoq.com/news/2015/01/golang-15-bootstrapped ,Go 最初是用 C 实现的,但在 1.5 版本时成为自托管的。 Bootstrapping 是用自身编译编译器的过程。 Go 开发人员编写了一个 C -> Go 转译器以将原始 C 编译器转换为 Go,然后他们手动编辑了 Go 代码以使其符合地道。

关于gcc - 为什么 Go 源码包含很多 .go 文件?它们是如何编译的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47734417/

相关文章:

ruby - 由于符号链接(symbolic link)错误,无法在 Mac OSX 10.8.1 中安装 ruby​​-1.9.2

c - int a=65; 如何实现? printf ("%c",a);在 GCC 中使用 C 语言工作?

go - 如何在 golang thrift 服务器中获取客户端的 IP

c - 使用 "make"C 编程(艰难地学习 C)

android - arm-linux-androideabi-g++ : -fuse-linker-plugin, 但找不到 liblto_plugin.so

c - 为什么 gcc 不优化全局变量?

xml - 逐行读取 XML 文件

go - Effective Go中的客户请求处理程序示例导致死锁?

c++ - 现代编译器是否优化了 unsigned int 在 for 循环中的使用?

python - 编译用于 mac OSX 10.8 上的 python 包装器的 C 库