Unable to build for linux on mac
When trying to build for linux on Mac Big Sur (11.0.1) I get an error. I have seen previous issue (https://github.com/h2non/bimg/issues/151) however it remains unsolved. I can build for Mac perfectly fine.
Code
package main
import "github.com/h2non/bimg"
func main() {
bimg.Read("jamaica.png")
}
Build attempt
GOOS=linux go build
Resulting error
# github.com/h2non/bimg
../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:93:49: undefined: Gravity
../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:133:29: undefined: Watermark
../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:139:34: undefined: WatermarkImage
../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:152:26: undefined: Angle
../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:181:31: undefined: Interpretation
../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:202:27: undefined: Options
../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:212:29: undefined: ImageMetadata
../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:218:35: undefined: Interpretation
../../../go/pkg/mod/github.com/h2non/[email protected]/image.go:234:25: undefined: ImageSize
../../../go/pkg/mod/github.com/h2non/[email protected]/resize.go:11:27: undefined: Options
../../../go/pkg/mod/github.com/h2non/[email protected]/resize.go:11:27: too many errors
Vips version: vips-8.10.2-Mon Oct 12 16:43:59 UTC 2020
Go version: go version go1.15.3 darwin/amd64
Go env:
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/wpc/Library/Caches/go-build"
GOENV="/Users/wpc/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/wpc/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/wpc/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/wpc/Projects/go/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/19/t_ym7y7974bcn4s78jn5kvr40000gn/T/go-build192137903=/tmp/go-build -gno-record-gcc-switches -fno-common"
If I build using
CGO_ENABLED=1 GOOS=linux go build
I get different error saying
# enumertest/debugbimg
/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: warning: ignoring file /var/folders/19/t_ym7y7974bcn4s78jn5kvr40000gn/T/go-link-246081632/go.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
Undefined symbols for architecture x86_64:
"__cgo_topofstack", referenced from:
__cgo_68a45036e746_Cfunc_has_alpha_channel in 000004.o
__cgo_68a45036e746_Cfunc_has_profile_embed in 000004.o
__cgo_68a45036e746_Cfunc_interpolator_window_size in 000004.o
__cgo_68a45036e746_Cfunc_vips_affine_interpolator in 000004.o
__cgo_68a45036e746_Cfunc_vips_autorot_bridge in 000004.o
__cgo_68a45036e746_Cfunc_vips_avifsave_bridge in 000004.o
__cgo_68a45036e746_Cfunc_vips_colourspace_bridge in 000004.o
...
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any suggestions?
I am having this same issue trying to build for windows / amd64, but under linux. Using WSLv2 I'm able to build / run just fine on linux, but can't target windows or mac os with the builds.
I met same problem, how is excuse me building Lord solved?
I'm still facing this issue building for Linux on Mac. The only option I see is directly trying to build it on Linux. I wonder why this happens though
I met same problem, so sad
The problem is the CGO part - you need the libvips headers for the system you want to compile for. Cross-compiling with CGO can be tricky.
same issue here
I met same problem,I get crazy!!!!
I met same problem,I get crazy!!!!
I found an alternative: https://www.libvips.org/API/current/using-cli.html
I met same problem,I get crazy!!!!
I found an alternative: https://www.libvips.org/API/current/using-cli.html First of all, Thank you~ You mean,you use the command line instead of code to solve the problem? I am a little confused about your alternative,I still cannot go build.
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o main .:
#0 68.14 # github.com/h2non/bimg
#0 68.14 /go/pkg/mod/github.com/h2non/[email protected]/image.go:93:49: undefined: Gravity
#0 68.14 /go/pkg/mod/github.com/h2non/[email protected]/image.go:133:29: undefined: Watermark
#0 68.14 /go/pkg/mod/github.com/h2non/[email protected]/image.go:139:34: undefined: WatermarkImage
#0 68.14 /go/pkg/mod/github.com/h2non/[email protected]/image.go:152:26: undefined: Angle
#0 68.14 /go/pkg/mod/github.com/h2non/[email protected]/image.go:181:31: undefined: Interpretation
#0 68.14 /go/pkg/mod/github.com/h2non/[email protected]/image.go:202:27: undefined: Options
#0 68.14 /go/pkg/mod/github.com/h2non/[email protected]/image.go:212:29: undefined: ImageMetadata
#0 68.14 /go/pkg/mod/github.com/h2non/[email protected]/image.go:218:35: undefined: Interpretation
#0 68.14 /go/pkg/mod/github.com/h2non/[email protected]/image.go:234:25: undefined: ImageSize
#0 68.14 /go/pkg/mod/github.com/h2non/[email protected]/resize.go:11:27: undefined: Options
#0 68.14 /go/pkg/mod/github.com/h2non/[email protected]/resize.go:11:27: too many errors
------
error: failed to solve: executor failed running [/bin/sh -c CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o main .]: exit code: 2
vips -v vips-8.13.0 macos M1
This library relies on CGO, you can't disable it.
Hi.. any update for this issue ? I got same issue.
~ vips -v
vips-8.13.3
CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -a -installsuffix cgo -o main . ⏎ ✹
# github.com/h2non/bimg
../../pkg/mod/github.com/h2non/[email protected]/image.go:93:49: undefined: Gravity
../../pkg/mod/github.com/h2non/[email protected]/image.go:133:29: undefined: Watermark
../../pkg/mod/github.com/h2non/[email protected]/image.go:139:34: undefined: WatermarkImage
../../pkg/mod/github.com/h2non/[email protected]/image.go:152:26: undefined: Angle
../../pkg/mod/github.com/h2non/[email protected]/image.go:181:31: undefined: Interpretation
../../pkg/mod/github.com/h2non/[email protected]/image.go:202:27: undefined: Options
../../pkg/mod/github.com/h2non/[email protected]/image.go:212:29: undefined: ImageMetadata
../../pkg/mod/github.com/h2non/[email protected]/image.go:218:35: undefined: Interpretation
../../pkg/mod/github.com/h2non/[email protected]/image.go:234:25: undefined: ImageSize
../../pkg/mod/github.com/h2non/[email protected]/resize.go:11:27: undefined: Options
../../pkg/mod/github.com/h2non/[email protected]/resize.go:11:27: too many errors
anyone has solved this?
This package relies on CGO, you can't disable it.
Hum I need use this lib on docker image alpine:3.15.6
#21 53.45 # github.com/h2non/bimg
#21 53.45 /go/pkg/mod/github.com/h2non/[email protected]/image.go:93:49: undefined: Gravity
#21 53.45 /go/pkg/mod/github.com/h2non/[email protected]/image.go:133:29: undefined: Watermark
#21 53.45 /go/pkg/mod/github.com/h2non/[email protected]/image.go:139:34: undefined: WatermarkImage
#21 53.45 /go/pkg/mod/github.com/h2non/[email protected]/image.go:152:26: undefined: Angle
#21 53.45 /go/pkg/mod/github.com/h2non/[email protected]/image.go:181:31: undefined: Interpretation
#21 53.45 /go/pkg/mod/github.com/h2non/[email protected]/image.go:202:27: undefined: Options
#21 53.45 /go/pkg/mod/github.com/h2non/[email protected]/image.go:212:29: undefined: ImageMetadata
#21 53.45 /go/pkg/mod/github.com/h2non/[email protected]/image.go:218:35: undefined: Interpretation
#21 53.45 /go/pkg/mod/github.com/h2non/[email protected]/image.go:234:25: undefined: ImageSize
#21 53.45 /go/pkg/mod/github.com/h2non/[email protected]/resize.go:11:27: undefined: Options
#21 53.45 /go/pkg/mod/github.com/h2non/[email protected]/resize.go:11:27: too many errors
I think both below lines can make a successful builds at different levels
GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o main .
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o main .
I had the same problem at windows and run it in Linux and I remember the prerequisites:
- libvips 8.3+ (8.8+ recommended)
- C compatible compiler such as gcc 4.6+ or clang 3.0+
I install both and everything works!
github.com/h2non/bimg
vendor/github.com/h2non/bimg/image.go:93:49: undefined: Gravity vendor/github.com/h2non/bimg/image.go:133:29: undefined: Watermark vendor/github.com/h2non/bimg/image.go:139:34: undefined: WatermarkImage vendor/github.com/h2non/bimg/image.go:152:26: undefined: Angle vendor/github.com/h2non/bimg/image.go:181:31: undefined: Interpretation 同样的问题 vendor/github.com/h2non/bimg/image.go:202:27: undefined: Options vendor/github.com/h2non/bimg/image.go:212:29: undefined: ImageMetadata vendor/github.com/h2non/bimg/image.go:218:35: undefined: Interpretation vendor/github.com/h2non/bimg/image.go:234:25: undefined: ImageSize vendor/github.com/h2non/bimg/resize.go:11:27: undefined: Options vendor/github.com/h2non/bimg/resize.go:11:27: too many errors
Hi I know how to fix this.
- This is not a "bimg" error. This is an OS architecture error. Mac arm and linux amd architecture.
- I had a Linux server on Ubuntu 18, but I needed to update it to 22. Because libc6 needs to be greater than 2.34. And you should check if the packages are installed: gcc libvips libvips-dev musl-dev libc6 And you have /lib/libc.musl-x86_64.so.1.
sudo apt install musl-dev
ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1
- To compile on Mac using m1. I'm building my own docker image. Dockerfile
FROM --platform=linux/amd64 golang:1.20.12
ENV PATH=/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/go/bin
RUN apt update && apt install -y gcc libvips-dev
Build it docker build -f Dockerfile -t sapsan4eg/go-project-tests:alpine-1.20-amd .
Then create DockerCompose file
version: "3.7"
services:
build:
platform: linux/amd64
image: sapsan4eg/go-project-tests:alpine-1.20-amd
volumes:
- "../:/src"
working_dir: /src
command: [ "/bin/sh", "-c", "build.sh" ]
build.sh
#!/bin/sh
echo "Building linux application:"
GOOS=linux GOARCH=amd64 go build -o bin/linux_amd64 ./cmd/main.go
And run it:
docker-compose -f docker-compose.yml run --rm build