chai2010 / webp

WebP decoder and encoder for Go (Zero Dependencies).
http://godoc.org/github.com/chai2010/webp
BSD 3-Clause "New" or "Revised" License
512 stars 89 forks source link

cross-compiling and linking on macOS fails with undefined webp* #33

Open prologic opened 3 years ago

prologic commented 3 years ago

Hello! 👋 I am currently unable to release twtxt v0.2.0 because of the following build/link errors when running through my release process with goreleaser:

   ⨯ release failed after 42.26s error=failed to build for darwin_amd64: # github.com/chai2010/webp
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:17:9: undefined: webpGetInfo
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:21:20: undefined: webpDecodeGray
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:34:20: undefined: webpDecodeRGB
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:47:20: undefined: webpDecodeRGBA
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:63:14: undefined: webpDecodeGrayToSize
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:77:14: undefined: webpDecodeRGBToSize
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:91:14: undefined: webpDecodeRGBAToSize
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:104:7: undefined: toGrayImage
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:105:14: undefined: webpEncodeGray
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:114:14: undefined: webpEncodeRGB
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:114:14: too many errors

The funny thing about this is that I actually develop on macOS and the binary otherwise builds just fine:

prologic@Jamess-iMac
Mon Aug 31 09:05:41
~/Projects/jointwt/twtxt
 (master) 0
$ make clean && make build && ./twtd -v
twtxt v0.1.0@1bbc215

Can someone please help? I'm not really sure what's going on 😢 and this is #blocking my release.

prologic commented 3 years ago

I think I fixed the macOS builds by removing the following form my .goreleaser.yml config:

-    env:
-      - CGO_ENABLED=0

But now I have a problem cross-compliing/building the Linux binaries; I assume its having trouble cross-compiliing them?

   ⨯ release failed after 5.35s error=failed to build for linux_amd64: # github.com/chai2010/webp
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:17:9: undefined: webpGetInfo
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:21:20: undefined: webpDecodeGray
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:34:20: undefined: webpDecodeRGB
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:47:20: undefined: webpDecodeRGBA
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:63:14: undefined: webpDecodeGrayToSize
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:77:14: undefined: webpDecodeRGBToSize
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:91:14: undefined: webpDecodeRGBAToSize
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:104:7: undefined: toGrayImage
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:105:14: undefined: webpEncodeGray
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:114:14: undefined: webpEncodeRGB
../../../go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:114:14: too many errors
prologic commented 3 years ago

Actually disregard my previous comment, the CGO_ENABLE=0 actually works and that's the way I build this in our Docker image Dockerfile and that's how we run this in production at twtxt.net; so the static build works just fine.

What doesn't work (as stated above) is the GoReleaser builds... 🤷‍♂️ If I can't solve this soon I'm going to have to come up with another way to do binary releases.

yuhang2 commented 3 years ago

The simplest way is build your code in Linux.

prologic commented 3 years ago

The simplest way is build your code in Linux.

How does this help solve the corss-compliation issue?

furiousassault commented 3 years ago

Hello. Thanks for your project once more.

Encountered the similar problem trying to build my project that uses your library on MacOS Catalina for Linux. So now I can't build it locally for several linux-based Docker images I use. Seems like this problem is discussed in repeating issues. Is there any progress on this?

icobani commented 3 years ago

+1

spaiki007 commented 3 years ago

Hello. Thanks for your project once more.

Encountered the similar problem trying to build my project that uses your library on MacOS Catalina for Linux. So now I can't build it locally for several linux-based Docker images I use. Seems like this problem is discussed in repeating issues. Is there any progress on this?

I only found such a solution...

Dockerfile.prod

FROM golang:stretch

WORKDIR /app

COPY . .

RUN go build -o /app/app

CMD ["/app/app"]

xs23933 commented 3 years ago

for MacOS my Plan

Install CEO compilation tools brew install FiloSottile/musl-cross/musl-cross

Build CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++ CGO_LDFLAGS="-static" go build -a -ldflags "-s -w" -o ./dist/server .

Allan-Nava commented 1 year ago

I have this error


#16 8.120 # github.com/chai2010/webp
#16 8.120 /go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:17:9: undefined: webpGetInfo
#16 8.120 /go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:21:20: undefined: webpDecodeGray
#16 8.120 /go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:34:20: undefined: webpDecodeRGB
#16 8.120 /go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:47:20: undefined: webpDecodeRGBA
#16 8.120 /go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:63:14: undefined: webpDecodeGrayToSize
#16 8.120 /go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:77:14: undefined: webpDecodeRGBToSize
#16 8.120 /go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:91:14: undefined: webpDecodeRGBAToSize
#16 8.120 /go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:104:7: undefined: toGrayImage
#16 8.120 /go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:105:14: undefined: webpEncodeGray
#16 8.120 /go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:114:14: undefined: webpEncodeRGB
#16 8.120 /go/pkg/mod/github.com/chai2010/webp@v1.1.0/webp.go:114:14: too many errors
#16 ERROR: executor failed running [/bin/sh -c CGO_ENABLED=0 GO111MODULE=on GOARCH=amd64 go build -ldflags "-s -w" 
Xun66 commented 1 year ago

for Windows my Plan

Install MinGW compilation tools brew install mingw-w64

Build CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ CGO_LDFLAGS="-static" go build -a -ldflags "-s -w" -o ./dist/server.exe .