New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go build gopkg.in/gographics/imagick.v3/imagick: invalid flag in pkg-config --cflags: -fopenmp #155

Closed
ghost opened this Issue Feb 14, 2018 · 7 comments

Comments

Projects
None yet
1 participant
@ghost
Copy link

ghost commented Feb 14, 2018

CentOS7

sh$ uname -a

Linux VM_0_15_centos 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Imagick.v3

rpm -Uvh ./init/ImageMagick-libs-7.0.7-22.x86_64.rpm
rpm -Uvh ./init/ImageMagick-7.0.7-22.x86_64.rpm
rpm -Uvh ./init/ImageMagick-devel-7.0.7-22.x86_64.rpm

sh$ pkg-config --cflags --libs MagickWand

-fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/include/ImageMagick-7 -lMagickWand-7.Q16HDRI -lMagickCore-7.Q16HDRI

sh$ go run somethingWithImagick.go

go build gopkg.in/gographics/imagick.v3/imagick: invalid flag in pkg-config --cflags: -fopenmp

sh$ go build somethingWithImagick.go

go build gopkg.in/gographics/imagick.v3/imagick: invalid flag in pkg-config --cflags: -fopenmp

imagick.v2

sh$ pkg-config --cflags --libs MagickWand

-fopenmp -I/usr/include/ImageMagick -lMagickWand -lMagickCor

sh$ go build main.go

go build gopkg.in/gographics/imagick.v2/imagick: invalid flag in pkg-config --cflags: -fopenmp

@justinfx

This comment has been minimized.

Copy link
Member

justinfx commented Feb 14, 2018

Does it work when doing a normal build or install of your program? I have seen go run fail to work properly on cgo programs.

@ghost

This comment has been minimized.

Copy link
Author

ghost commented Feb 14, 2018

it works well when I build or run a program without importing imagick

@justinfx

This comment has been minimized.

Copy link
Member

justinfx commented Feb 14, 2018

Thanks for answering that. I was getting at whether it would work when using go build with imagick, and you covered it. I think you are hitting this: golang/go#23739
Are you using go-1.9.4? They introduced security updates in cgo which prevent various flags from being used.

It was reported already to be added to the whitelist:
golang/go#23749

The workaround for now is to manually whitelist them by setting CGO_CFLAGS_ALLOW or CGO_LDFLAGS_ALLOW

@ghost

This comment has been minimized.

Copy link
Author

ghost commented Feb 15, 2018

sh$ go version

go version go1.9.4 linux/amd64

sh$ go env

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/bin/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build718350618=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

@ghost

This comment has been minimized.

Copy link
Author

ghost commented Feb 15, 2018

sh$ echo ${CGO_LDFLAGS_ALLOW}

.*.a$

sh$ go run main.go

go build gopkg.in/gographics/imagick.v2/imagick: invalid flag in pkg-config --cflags: -fopenmp

sh$ go run -tags no_pkgconfig main.go

gopkg.in/gographics/imagick.v2/imagick

../../gopkg.in/gographics/imagick.v2/imagick/affine_matrix.go:8:29: fatal error: wand/MagickWand.h: No such file or directory
#include <wand/MagickWand.h>
^
compilation terminated.

@justinfx

This comment has been minimized.

Copy link
Member

justinfx commented Feb 15, 2018

This is the workaround, from what the ticket says:

export CGO_CFLAGS_ALLOW='-fopenmp'

The failing flag is a compile flag, so you need to manually whitelist it.

go run -tags no_pkgconfig main.go

You can't do this without telling it explicit CGO_CFLAGS and CGO_LDFLAGS. That turns off pkg-config which means its now not finding ImageMagick

@justinfx

This comment has been minimized.

Copy link
Member

justinfx commented Apr 2, 2018

Closing this since the problem relates to the cgo whitelist in the latest Go release.

@justinfx justinfx closed this Apr 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment