kolesa-team / go-webp

Simple and fast webp library for golang
MIT License
225 stars 36 forks source link

Build on FreeBSD? #26

Closed bwmarrin closed 1 year ago

bwmarrin commented 1 year ago

Any change you (or someone) has any tips or steps on how to build this library on FreeBSD? I'm not that keen on working with cgo :(

I've installed the webp package and that includes the header files in /usr/local/include/webp and libs in /usr/local/lib/libwebp*

When I try to build the example encode I get the below errors. I'm not sure how to tell it to look in the /usr/local/include/webp folder for the encode.h and decode.h files.

o build
# github.com/kolesa-team/go-webp/encoder
../../encoder/encoder.go:29:10: fatal error: 'webp/encode.h' file not found
#include <webp/encode.h>
         ^~~~~~~~~~~~~~~
1 error generated.
# github.com/kolesa-team/go-webp/decoder
../../decoder/decoder.go:28:10: fatal error: 'webp/decode.h' file not found
#include <webp/decode.h>
         ^~~~~~~~~~~~~~~
1 error generated.
bwmarrin commented 1 year ago

Of course - after asking a question I think I've come up with a solution. The below command will tell Go where to look for these files.

CGO_CFLAGS=-I/usr/local/include CGO_LDFLAGS=-L/usr/local/lib go build

This can also be done by adding the below two lines to the top of both the decoder.go and encoder.go files near the rest of the cgo build lines.

#cgo freebsd CFLAGS: -I/usr/local/include
#cgo freebsd LDFLAGS: -L/usr/local/lib