pixiv / go-libjpeg

An implementation of Go binding for libjpeg (or libjpeg-turbo).
BSD 3-Clause "New" or "Revised" License
156 stars 52 forks source link

getting error while go get github.com/pixiv/go-libjpeg/jpeg #65

Open ashu171996 opened 3 years ago

ashu171996 commented 3 years ago
# github.com/pixiv/go-libjpeg/jpeg
go/pkg/mod/github.com/pixiv/go-libjpeg@v0.0.0-20190822045933-3da21a74767d/jpeg/compress.go:6:10: fatal error: jpeglib.h: No such file or directory
 #include "jpeglib.h"
          ^~~~~~~~~~~
compilation terminated.

The above block appears while executing go get, any idea what to do next. Any help would be appreciated. Best regards Ashutosh

ashu171996 commented 3 years ago

My go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/ashutoshp/.cache/go-build" GOENV="/home/ashutoshp/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/ashutoshp/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/ashutoshp/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.16" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" 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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2380541700=/tmp/go-build -gno-record-gcc-switches"

ivanovaleksey commented 3 years ago

@ashu171996 you have to specify location of the header file (also I guess the library). You do that by setting CGO_LDFLAGS and CGO_CPPFLAGS variables See similar issue

scaszoo commented 2 years ago

@ashu171996 'sudo apt-get install libjpeg-dev' should solve your issue :-)

For mac e.g. brew install jpeg helps to retrieve the neccessary includes and libs. Running e.g. CGO_LDFLAGS="-L/opt/homebrew/Cellar/jpeg/9d/lib -lm" CGO_CPPFLAGS="-I/opt/homebrew/Cellar/jpeg/9d/include" go get github.com/pixiv/go-libjpeg would be able to load the package. Adjust the version (9d) if it has changed.

Edit: It's also possible to just use CGO_LDFLAGS="-L/opt/homebrew/lib -lm" CGO_CPPFLAGS="-I/opt/homebrew/include" go get github.com/pixiv/go-libjpeg

Or executing in your shell: export CPATH=/opt/homebrew/include export LIBRARY_PATH=/opt/homebrew/lib or adding it to your shell rc file.