Hello, As described in https://go.googlesource.com/gollvm/#seetheir, you will generally want to run "go build" in order to see the correct invocation of llvm-goc for your use case.
In your case (building a Go file that uses CGO), there is a lot happening "under the hood" when you do the build -- it's not a single compiler invocation. I recommend that you try the following: go build -x -work somecgo.go 1> err.txt 2>&1 then take a look at the commands that "go build" is executing to carry out the build. You'll first see the invocation of the "cgo" tool, something like this TERM='dumb' CGO_LDFLAGS='"-g" "-O2"' /x/gollvm-install/tools/cgo -objdir ./go-build3209048615/b001/ -importpath command-line-arguments -gccgo -- -I ./go-build3209048615/b001/ -g -O2 -fsplit-stack ./somecgo.go The cgo tool analyzes the Go source file and emits new boilerplate / glue files (both C files and Go files) needed to connect up the two chunks of code in the file (the C chunk and the Go chunk). Next you'll see more invocations of the C and Go compilers, e.g. things like TERM='dumb' /usr/bin/clang-10 -I /tmp -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -funwind-tables -I ./ -g -O2 -fsplit-stack -o ./_x002.o -c somecgo.cgo2.c and /x/gollvm-install/bin/llvm-goc -c -O2 -g -m64 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -fgo-relative-import-path=_/tmp -o ./go-build3209048615/b001/_go_.o -I ./go-build3209048615/b001/_importcfgroot_ ./go-build3209048615/b001/_cgo_gotypes.go ./go-build3209048615/b001/somecgo.cgo1.go ./go-build3209048615/b001/_gomod_.go to generate objects that feed into the final link. If you want to collect the LLVM IR, you'll need to capture and replay all of these compilations with the appropriate compiler options (e.g. "-emit-llvm") and capture the results. Hope this helps. Than On Thu, Jun 10, 2021 at 2:27 AM Peng Deng <dws...@outlook.com> wrote: > Hi, I have the following program > > package main > > /* > #include <stdio.h> > > static void SayHello(const char* s) { > puts(s); > } > */ > import "C" > > func main() { > C.SayHello(C.CString("Hello, World\n")) > } > > I want to compile this program to LLVM IR with gollvm, the compilation > instruction is as follows: > > llvm-goc -emit-llvm -c -O0 goc.go -o goc.bc > > The errors are as follows: > > goc.go:10:9: error: import file 'C' not found > goc.go:13:5: error: reference to undefined name 'C' > goc.go:13:16: error: reference to undefined name 'C' > > What's wrong with my compilation instruction? How could I compile this > program to LLVM IR? > > I would appreciate it if someone could help me. > > Thank you! > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/614dface-3e06-4050-8ea2-bf1ffd0c5349n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/614dface-3e06-4050-8ea2-bf1ffd0c5349n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CA%2BUr55ErDC%2BBU-Pm3740FgD-dFBxu7eVLFgKGsyd880m59DHkA%40mail.gmail.com.