go-face icon indicating copy to clipboard operation
go-face copied to clipboard

Issue with go get on M1 MacOS

Open dtaivpp opened this issue 2 years ago • 6 comments

Hey all, pretty new to go and having a problem with go get on MacOS 12.2/Go 1.17.6 on M1.

Here is what I am facing:

face-detector % go get github.com/Kagami/go-face 
# github.com/Kagami/go-face
clang: error: the clang compiler does not support '-march=native'

I am not sure if I am missing some flag that would allow this to build. Here is my go env:

face-detector % go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/<username>/Library/Caches/go-build"
GOENV="/Users/<username>/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/<username>/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/<username>/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.17.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.17.6/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/<username>/Development/face-detector/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/j1/gdnt9_0d3811nn7d8t63hbc80000gn/T/go-build658795374=/tmp/go-build -gno-record-gcc-switches -fno-common"

Any recommendations? I am not seeing where -march=native is set. There was a stack overflow thread that suggested using -mcpu=apple-m1 however I am not seeing where to put that.

dtaivpp avatar Feb 22 '22 16:02 dtaivpp

modify face.go at this project

package face

// #cgo CXXFLAGS: -std=c++1z -Wall -O3 -DNDEBUG -mcpu=apple-m1

gougo avatar Jun 07 '22 05:06 gougo

another solutions is update clang with brew

lang: error: the clang compiler does not support '-march=native'

1° - Install llvm con brew brew install llvm 2° - Check clang version

cd /opt/homebrew/opt/llvm
.clang --version

Result:

Homebrew clang version 15.0.6
Target: arm64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin

3° - modify path with the new version, for example add to .zshrc export PATH="/opt/homebrew/opt/llvm/bin:$PATH"

nodoyuna avatar Jan 11 '23 21:01 nodoyuna

I tried the solution above, and now it gets an error

classify.cc:2:10: fatal error: 'dlib/graph_utils.h' file not found

Exegetech avatar Feb 02 '23 05:02 Exegetech

I tried the solution above, and now it gets an error

classify.cc:2:10: fatal error: 'dlib/graph_utils.h' file not found

try CPLUS_INCLUDE_PATH=/opt/homebrew/Cellar/jpeg/9d/include/:/opt/homebrew/Cellar/dlib/19.24_1/include LD_LIBRARY_PATH=/opt/homebrew/Cellar/dlib/19.24_1/lib/:/opt/homebrew/Cellar/jpeg/9d/lib/ LIBRARY_PATH=/opt/homebrew/Cellar/dlib/19.24_1/lib/:/opt/homebrew/Cellar/jpeg/9d/lib/ go build

chaosue avatar Jul 16 '23 05:07 chaosue

Same error here, even with setting LIBRARY_PATH (for me, CPLUS_INCLUDE_PATH and LD_LIBRARY_PATH were already setup correctly). Any hints @chaosue @Kagami @gougo @Exegetech @nodoyuna @dtaivpp ?

adrien3d avatar Apr 20 '24 06:04 adrien3d

Fixed by copying dlib in $GOPATH/pkg/path/to/go-faceand changing import in classify.cc

adrien3d avatar Apr 20 '24 07:04 adrien3d