go-graphviz
go-graphviz copied to clipboard
Unable to build binary for project with a dependency on go-graphviz
Based on this example, I put together a tiny example repo bringing in go-graphviz.
I'm able to run go run
successfully, but I'm not able to build binaries -- either for mac, or cross-compiling for linux.
package main
import (
"github.com/goccy/go-graphviz"
)
func main() {
g := graphviz.New()
graph, _ := g.Graph()
a, _ := graph.CreateNode("a")
b, _ := graph.CreateNode("b")
graph.CreateEdge("a2b", a, b)
g.RenderFilename(graph, graphviz.PNG, "./graph.png")
}
Output:
./build.sh
#set -euo pipefail
go run cmd/graphviz/main.go
+ go run cmd/graphviz/main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ./cmd/graphviz/main ./cmd/graphviz
+ CGO_ENABLED=0
+ GOOS=darwin
+ GOARCH=amd64
+ go build -o ./cmd/graphviz/main ./cmd/graphviz
package github.com/mattfenwick/graphviz-test/cmd/graphviz
imports github.com/goccy/go-graphviz
imports github.com/goccy/go-graphviz/cgraph
imports github.com/goccy/go-graphviz/internal/ccall: build constraints exclude all Go files in /Users/mfenwick/go/pkg/mod/github.com/goccy/[email protected]/internal/ccall
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./cmd/graphviz/main ./cmd/graphviz
+ CGO_ENABLED=0
+ GOOS=linux
+ GOARCH=amd64
+ go build -o ./cmd/graphviz/main ./cmd/graphviz
package github.com/mattfenwick/graphviz-test/cmd/graphviz
imports github.com/goccy/go-graphviz
imports github.com/goccy/go-graphviz/cgraph
imports github.com/goccy/go-graphviz/internal/ccall: build constraints exclude all Go files in /Users/mfenwick/go/pkg/mod/github.com/goccy/[email protected]/internal/ccall
I'm working on a Mac.
How can I build mac and linux binaries where I'm including go-graphviz ?
Any update on this? I am facing the same issues cross-compiling this project using Bazel:
ERROR: WORKDIRvendor/github.com/goccy/go-graphviz/internal/ccall/BUILD.bazel:3:11: GoCompilePkg vendor/github.com/goccy/go-graphviz/internal/ccall/ccall.a failed: (Exit 1): builder failed: error executing command bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix darwin_amd64 -src vendor/github.com/goccy/go-graphviz/internal/ccall/ccall.go -src ... (remaining 79 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox builder failed: error executing command bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix darwin_amd64 -src vendor/github.com/goccy/go-graphviz/internal/ccall/ccall.go -src ... (remaining 79 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
vendor/github.com/goccy/go-graphviz/internal/ccall/ccall.go:27:10: fatal error: 'config.h' file not found
#include "config.h"
^~~~~~~~~~
1 error generated.
compilepkg: error running subcommand external/go_sdk/pkg/tool/darwin_amd64/cgo: exit status 2
me too, how to fix?
go-graphviz is cgo project. So CGO_ENABLED=1
value always required to build .
If you want to build static binary, specify --ldflags '-extldflags "-static"'
instead of CGO_ENABLED=0
go-graphviz is cgo project. So
CGO_ENABLED=1
value always required to build . If you want to build static binary, specify--ldflags '-extldflags "-static"'
instead ofCGO_ENABLED=0
Can we have this as part of REAME
document? It seems to be a frequently asked question
Any update on this? I am facing the same issues cross-compiling this project using Bazel:
ERROR: WORKDIRvendor/github.com/goccy/go-graphviz/internal/ccall/BUILD.bazel:3:11: GoCompilePkg vendor/github.com/goccy/go-graphviz/internal/ccall/ccall.a failed: (Exit 1): builder failed: error executing command bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix darwin_amd64 -src vendor/github.com/goccy/go-graphviz/internal/ccall/ccall.go -src ... (remaining 79 argument(s) skipped) Use --sandbox_debug to see verbose messages from the sandbox builder failed: error executing command bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix darwin_amd64 -src vendor/github.com/goccy/go-graphviz/internal/ccall/ccall.go -src ... (remaining 79 argument(s) skipped) Use --sandbox_debug to see verbose messages from the sandbox vendor/github.com/goccy/go-graphviz/internal/ccall/ccall.go:27:10: fatal error: 'config.h' file not found #include "config.h" ^~~~~~~~~~ 1 error generated. compilepkg: error running subcommand external/go_sdk/pkg/tool/darwin_amd64/cgo: exit status 2
Hi were you able to resolve this? I'm having the same problem, not sure what to do.
tried to solve the same problem as descrived above, doing GOOS=linux GOARCH=amd64 GOHOSTOS=darwin GOHOSTARCH=amd64 CGO_ENABLED=1 go build -v -o bin/service
however, I receive more errors in result:
# runtime/cgo
linux_syscall.c:67:13: error: call to undeclared function 'setresgid'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
linux_syscall.c:67:13: note: did you mean 'setregid'?
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:593:6: note: 'setregid' declared here
linux_syscall.c:73:13: error: call to undeclared function 'setresuid'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
linux_syscall.c:73:13: note: did you mean 'setreuid'?
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:595:6: note: 'setreuid' declared here
make: *** [native] Error 1
CGO_ENABLED=1
v
Facing the same issue after following the suggestions from the thread. I tried GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o bin/some_name-linux main.go
and bumped into this issue. Any solution?