h2non / bimg

Go package for fast high-level image processing powered by libvips C library
https://pkg.go.dev/github.com/h2non/bimg?tab=doc
MIT License
2.65k stars 337 forks source link

go build fails for vips-8.14.1 #438

Closed harshav17 closed 1 year ago

harshav17 commented 1 year ago

I have a simple program which converts a png to webp image.

package main

import (
    "fmt"
    "os"

    "github.com/h2non/bimg"
)

func main() {
    file := "test.jpg"
    dat, err := os.ReadFile(file)
    if err != nil {
        fmt.Println("Hello, World!")
    }

    options := bimg.Options{
        NoAutoRotate: true,
        Width:        400,
        Height:       400,
        Crop:         true,
        Gravity:      bimg.GravityCentre,
        Type:         bimg.WEBP,
    }
    _, err = bimg.NewImage(dat).Process(options)
    if err != nil {
        fmt.Println("Hello, World!")
    }
}

I made the mistake of upgrading vips to 8.14.1 from 8.13.3 (where it works fine). go build of this program now fails with...

/usr/local/go/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
ld: warning: directory not found for option '-L/opt/homebrew/Cellar/vips/8.13.3/lib'
ld: warning: directory not found for option '-L/opt/homebrew/Cellar/glib/2.74.0/lib'
ld: library not found for -lvips
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any pointers on how to resolve this issue?

Thanks in advance.

mlilley commented 1 year ago

This is because go is caching the previously built bimg dependency, built on your system against version 8.13.3 of vips.

When you upgraded vips to 8.14.1, version 8.13.3 was removed from your system, and the cached bimg build can no longer find it to link against it.

To fix, force go to discard the cached build of bimg and rebuild it against whatever libs are currently installed on your system (ie: vips 8.14.1) using go build -a.

harshav17 commented 1 year ago

Yeah, that was it! Thank you. I was able to clean the cache with go clean --cache and was able to fix that issue for future runs as well.

nunosilva800 commented 1 year ago

go clean --cache Thank you, you are a life saver!