gcc - golang 在使用和不使用 cgo 进行构建时使用的汇编程序

标签 gcc assembly go package cgo

假设我有一个 golang 包,其中包含一些汇编代码:

 demopkg/
   source1.go
   source2.go
   asm_amd64.s

如果我尝试使用 go build 构建它,工具链将使用 go tool asm 来组装 *.s 文件。

但是如果我将 Cgo 添加到混合物中,通过将单个 import "C" 放入任何源代码,go 将切换到 gcc 汇编程序。

我可以通过执行 go build -n 看到它。第一种情况下对 /usr/local/go/pkg/tool/linux_amd64/asm 的调用被对 gcc 的调用所取代。除此之外,它开始提示语法错误。

是否记录了此行为,以便我可以依靠它来维护我的包?我可以强制 go build 使用一个确切的汇编器吗?

最佳答案

是的,它在 cgo documentation

When the Go tool sees that one or more Go files use the special import "C", it will look for other non-Go files in the directory and compile them as part of the Go package. Any .c, .s, or .S files will be compiled with the C compiler. Any .cc, .cpp, or .cxx files will be compiled with the C++ compiler. Any .h, .hh, .hpp, or .hxx files will not be compiled separately, but, if these header files are changed, the C and C++ files will be recompiled. The default C and C++ compilers may be changed by the CC and CXX environment variables, respectively; those environment variables may include command line options.

关于gcc - golang 在使用和不使用 cgo 进行构建时使用的汇编程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35587395/

相关文章:

php - 从 PHP 的 shell_exec() 函数执行 Golang 二进制文件

c - 如何知道任何库函数(中止)调用是否在源代码中多次使用?

gcc - 错误 : ‘avcodec_send_packet’ was not declared in this scope

c++ - 绕过 gcc 中的静态链接顺序问题

ubuntu - gcc/Ubuntu : Finding the disk path to the library used at linkage

c - Visual Studio C 编译器中是否有单独的 bitset64 内在函数?

linux - (宏语言处理器 m4)如何运行 resp。在 Ubuntu 13.4 上编译 .m4 程序?

c - GCC/对象转储 : Generating compilable/buildable assembly (interspersed with C/C++) source?

xml - 获取原始元素表示,包括开始和结束标签

go - Go 数组的索引是什么?