Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Unable to build binary for project with a dependency on go-graphviz #43

Closed
mattfenwick opened this issue May 16, 2021 · 7 comments · Fixed by #90
Closed

Unable to build binary for project with a dependency on go-graphviz #43

mattfenwick opened this issue May 16, 2021 · 7 comments · Fixed by #90

Comments

@mattfenwick
Copy link

mattfenwick commented May 16, 2021

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/go-graphviz@v0.0.9/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/go-graphviz@v0.0.9/internal/ccall

I'm working on a Mac.

How can I build mac and linux binaries where I'm including go-graphviz ?

@mattfenwick mattfenwick changed the title Unable to compile project with a dependency on go-graphviz Unable to build binary for project with a dependency on go-graphviz May 16, 2021
@jotadrilo
Copy link

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

@hehuilei
Copy link

me too, how to fix?

@goccy
Copy link
Owner

goccy commented Apr 19, 2022

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

@t1anz0ng
Copy link

t1anz0ng commented Aug 2, 2022

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

Can we have this as part of REAME document? It seems to be a frequently asked question

@anhducle98
Copy link

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.

@n0vice
Copy link

n0vice commented May 1, 2023

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

@kuldeep0020
Copy link

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?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants