chai2010 / webp

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

Error for Linux Build #48

Open smalloff opened 2 years ago

smalloff commented 2 years ago

Hi! My params for Linux release.

set GOARCH=amd64 set GOOS=linux go build -ldflags "-s -w"

Output:

C:\Users\admin\go\pkg\mod\github.com\chai2010\webp@v1.1.1\webp.go:22:9: undefined: webpGetInfo C:\Users\admin\go\pkg\mod\github.com\chai2010\webp@v1.1.1\webp.go:26:20: undefined: webpDecodeGray C:\Users\admin\go\pkg\mod\github.com\chai2010\webp@v1.1.1\webp.go:39:20: undefined: webpDecodeRGB C:\Users\admin\go\pkg\mod\github.com\chai2010\webp@v1.1.1\webp.go:52:20: undefined: webpDecodeRGBA C:\Users\admin\go\pkg\mod\github.com\chai2010\webp@v1.1.1\webp.go:68:14: undefined: webpDecodeGrayToSize C:\Users\admin\go\pkg\mod\github.com\chai2010\webp@v1.1.1\webp.go:82:14: undefined: webpDecodeRGBToSize C:\Users\admin\go\pkg\mod\github.com\chai2010\webp@v1.1.1\webp.go:96:14: undefined: webpDecodeRGBAToSize C:\Users\admin\go\pkg\mod\github.com\chai2010\webp@v1.1.1\webp.go:109:7: undefined: toGrayImage C:\Users\admin\go\pkg\mod\github.com\chai2010\webp@v1.1.1\webp.go:110:14: undefined: webpEncodeGray C:\Users\admin\go\pkg\mod\github.com\chai2010\webp@v1.1.1\webp.go:119:14: undefined: webpEncodeRGB C:\Users\admin\go\pkg\mod\github.com\chai2010\webp@v1.1.1\webp.go:119:14: too many errors

Installed TDM-GCC OS Windows 10. Golang version 1.18.4

How can I compile for Linux? When building for Windows, there are no errors. Thanks!

Pukka922 commented 2 years ago

I have the same error on a docker build.

smalloff commented 2 years ago

I have the same error on a docker build.

Try this library github.com/nickalie/go-webpbin

michu91 commented 2 years ago

@smalloff @Pukka922 try to add env CGO_ENABLED=1

ydylla commented 1 year ago

For me Zig worked great as compiler when cross compiling from Windows to Linux.
I used these env variables:

GOOS=linux
GOARCH=amd64
CGO_ENABLED=1
CC="zig cc -target x86_64-linux-musl"
CXX="zig c++ -target x86_64-linux-musl"

Inspired by this article: https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho

aerosouund commented 11 months ago

Same issue, maintainers helps us out here

jphastings commented 3 months ago

I just came across this — I think this is because you're using Alpine Linux; which uses a different set of C libraries (which are apparently incompatible with this package!)

Try using an Ubuntu or Debian go image (golang:1.22-bookworm worked for me) and see if it works — if so, then this is your issue.

Achno commented 3 months ago

I tried using goreleaser for my project to automate creating the tarballs and faced the exact same issue.

Would it work if i add the CGO_ENABLED=1 env ? Anyone who faced the same issue ?

jackfiallos commented 3 weeks ago

Hey everyone, I encountered the same issue when building my app, so based on @jphastings comment about Alpine's musl C library being incompatible, I switched from golang:1.21.13-alpine3.20 to golang:1.22-bookworm, enabled CGO (CGO_ENABLED=1), and added the libwebp-dev package in the Dockerfile:

FROM golang:1.22-bookworm

RUN apt-get update && apt-get install -y libwebp-dev

RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o app .

I also used a multi-stage build with debian:bookworm-slim for the final image to keep it minimal.

This strategy fixed the issue for me, hope this helps others too!