The Go compiler does not compile cgo codes.

461 views
Skip to first unread message

Fannie Zhang

unread,
Mar 31, 2021, 5:12:56 AM3/31/21
to golan...@googlegroups.com

Hi all,

 

If we use “go tool compile -S ” to compile a cgo file hello.go,  the error “could not import "C": file not found” will be reported.

 

The cgo file hello.go

“  

import "C"

import “fmt”

 

func main() {

        fmt.println("hello")

}

 

This behavior of compiler seems unreasonable to me.  Because sometimes we want to see the assembly code of some cgo files.

I think Go compiler should print the assembly code for Go codes and ignore C codes.

Can we change its behavior?

 

Thanks,

Fannie

 

 

Josh Bleecher Snyder

unread,
Mar 31, 2021, 10:26:47 AM3/31/21
to Fannie Zhang, golan...@googlegroups.com
Try:

go build -gcflags=-S hello.go




--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-dev/AM7PR08MB5415A67E6B62295E00A6F306947C9%40AM7PR08MB5415.eurprd08.prod.outlook.com.

Fannie...@arm.com

unread,
Mar 31, 2021, 9:58:58 PM3/31/21
to golang-dev
On Wednesday, March 31, 2021 at 10:26:47 PM UTC+8 josh...@gmail.com wrote:
Try:

go build -gcflags=-S hello.go

It works. I forgot this usage. Thank you. 

Best regards,
Reply all
Reply to author
Forward
0 new messages