Skip to content
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

Add make variables for Mac OS 12.5/ARM #85

Open
joshfrench opened this issue Aug 12, 2022 · 5 comments
Open

Add make variables for Mac OS 12.5/ARM #85

joshfrench opened this issue Aug 12, 2022 · 5 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@joshfrench
Copy link

Env:

go version go1.19 darwin/arm64
OS: macOS Monterey 12.5

I've previously installed Pistol on OS 11.6/Intel with no issues, but on a new machine I'm unable to install or build it.

Steps:

$ brew install libmagic
...
(installation succeeds)

$ brew link libmagic
Already linked: /opt/homebrew/Cellar/libmagic/5.42

$ go install github.com/doronbehar/pistol/cmd/[email protected]
../../go/pkg/mod/github.com/doronbehar/[email protected]/magicmime.go:28:11: fatal error: 'magic.h' file not found

$ CGO_CFLAGS="-I${HOMEBREW_PREFIX}/Cellar/libmagic/5.42/include" go install github.com/doronbehar/pistol/cmd/[email protected]
/opt/homebrew/Cellar/go/1.19/libexec/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
ld: library not found for -lmagic
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I get the last error (ld: library not found for -lmagic) when attempting to build from source, as well.

I'm mostly posting this in case other OS X users run into it -- the problem seems to be with libmagic, and I suspect you're unable to help troubleshoot OS X anyway :)

@joshfrench
Copy link
Author

Aha! I needed to pass another flag when building:

CGO_CFLAGS="-I${HOMEBREW_PREFIX}/include" CGO_LDFLAGS="-L${HOMEBREW_PREFIX}/lib" go build

@doronbehar
Copy link
Owner

Aha! I needed to pass another flag when building:

CGO_CFLAGS="-I${HOMEBREW_PREFIX}/include" CGO_LDFLAGS="-L${HOMEBREW_PREFIX}/lib" go build

Do you think @joshfrench this could be empbedded into the makefile? I mean, could we detect that we are building on a macos machine, and add these flags automatically?

@joshfrench
Copy link
Author

You could shell out and check uname -sp (although I'm not sure if -p is present on every platform, so maybe a combination of uname and arch?)

Either way you're looking for Darwin and one of x86_64 or arm64. It's been a while but I think pistol built fine on a previous Intel mac, so you'd only need to add the flags when you detect an Apple chip.

@joshfrench
Copy link
Author

I'd send a PR but my make syntax is pretty rusty :)

@doronbehar doronbehar changed the title Build error on Mac OS 12.5/ARM Add make variables for Mac OS 12.5/ARM Sep 4, 2022
@doronbehar doronbehar reopened this Sep 4, 2022
@doronbehar doronbehar added help wanted Extra attention is needed good first issue Good for newcomers labels Sep 4, 2022
@doronbehar
Copy link
Owner

Hey, you may want to check the new 0.4.1 release which not necessarily include many new features, but it does include statically compiled binary for aarch64. I still think this issue is worth staying open, for any Mac OS user that will want to build and help develop pistol in the future, so I'm keeping this open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants