cosmos72 / gomacro

Interactive Go interpreter and debugger with REPL, Eval, generics and Lisp-like macros

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I'm unable to compile code importing gomacro on Mac OS m1 pro

tonyalaribe opened this issue · comments

I have code which looks like below:

import 	"github.com/cosmos72/gomacro/fast"

func main() {
	intp := fast.New()
	_ = intp
}

And when I execute it, I get the error:

❯ go run doctests.go 
# command-line-arguments
/usr/local/Cellar/go/1.18.1/libexec/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: framework not found CoreFoundation
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)

What can i do to fix this/workaround it

I am not an expert of the new Mac OS M1.

Having said that, for some reason the Go toolchain invokes the system linker ld - which on Mac OS is provided by Xcode.

A possible solution is probably to install Xcode - but see also https://stackoverflow.com/questions/66908875/mac-os-big-sur-r-compilation-error-ld-framework-not-found-corefoundation?answertab=trending#tab-top

As an alternative, you can try setting the environment variable CGO_ENABLED=0, as for example:

CGO_ENABLED=0 go run doctests.go

Using CGO_ENABLED=0 worked. But i wonder why.

Because it uses Go toolchain internal linker instead of invoking the system linker.

A side effect of doing CGO_ENABLED=0 is that I get this error if I try to import a folder as a package.

// debug: running "go get github.com/apitoolkit/doctester" ...
go: added github.com/apitoolkit/doctester v0.0.0-00010101000000-000000000000
// debug: running "go mod tidy" ...
// debug: compiling plugin "/Users/tonyalaribe/go/src/gomacro.imports/gomacro_pid_69950/import_1" ...
# gomacro.imports/import_1
loadinternal: cannot find runtime/cgo
panic: error loading plugin "/Users/tonyalaribe/go/src/gomacro.imports/gomacro_pid_69950/import_1/import_1.so": plugin: not implemented

image

Yes, I was concerned this would be a side effect.

To import third-party package, gomacro first compiles it as a plugin (using Go toolchain), then loads it using plugin.Open() which in turn uses the C function dlopen().
And CGO_ENABLED=0 removes interoperability with C code, so dlopen() is no longer available.

The only solution is to fix the initial error you reported

/usr/local/Cellar/go/1.18.1/libexec/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: framework not found CoreFoundation
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)

which is definitely outside my expertise.

The discussion https://stackoverflow.com/questions/66908875/mac-os-big-sur-r-compilation-error-ld-framework-not-found-corefoundation I linked above may (or may not) help - in any case it's definitely an issue related with Xcode.

Yeah, you're right. I'm trying to reinstall xcode command line tools and hoping that it works.

Running the following fixed the issue. Thanks for supporting through this:

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install