如何构建一个可以跨 macOS 版本的 Go 应用程序?

huangapple go评论79阅读模式
英文:

How to build a Go app that can cross-macOS-version?

问题

这是我最近创建的 macOS 应用程序:https://github.com/evillt/macmineable-release
这是我遇到的问题:https://github.com/evillt/macmineable-release/issues/18

我在我的设备上构建了这个应用程序,它可以在任何 Big Sur 设备上正常运行,甚至是 M1 设备,但无法在 Catalina(10.15)上运行。

所以我想要构建一个可以在多个 macOS 版本上运行的单个应用程序版本。

非常感谢任何建议!

更新

我的设备是 MacBook Pro 2015,Intel I5 芯片,Big Sur 11.5.2。

我在我的设备上构建了这个应用程序,它可以在以下设备上正常运行:

  • 我的设备
  • MacBook 12 英寸,Big Sur 11.0
  • 其他 M1 设备(Big Sur 11.0 或更高版本)

但无法在 MacBook Pro Intel I7 Catalina 10.15.7 上运行。问题在这里

这就是我所知道的。

英文:

Here is my recently created macOS app: https://github.com/evillt/macmineable-release
and here is my facing issue: https://github.com/evillt/macmineable-release/issues/18

I built the app on my machine it can run normally on any BigSur device, even M1 devices, but can not run on Catalina(10.15).

So what I want is to build a version that can run on multi-macOS-version with a single app.

Huge thanks for any suggestions!

update

My device is MacBook Pro 2015, Intel I5 chip, Big Sur 11.5.2.

I build this app on my device, it can run normally on:

  • My device
  • MacBook 12-inch Big Sur 11.0
  • Other M1 devices (Big Sur 11.0 or above)

But can not run on MacBook Pro Intel I7 Catalina 10.15.7. The issue here.

That is all I know.

答案1

得分: 2

你需要在构建过程中更改Go使用的CC编译器。

运行以下命令查看当前的CC编译器:

go env CC

输出应该是clang,这通常使用/usr/bin/clang路径下的版本。

如果你已经安装了Xcode,或者只安装了Command Line Tools,你可以看到最近几个主要版本的各种版本,例如:

$ find /Library/Developer/CommandLineTools -name clang

/Library/Developer/CommandLineTools/usr/bin/clang
/Library/Developer/CommandLineTools/usr/lib/clang
/Library/Developer/CommandLineTools/usr/lib/swift/clang
/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/A/lib/clang
/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A/lib/clang
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/A/lib/clang
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A/lib/clang
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/A/lib/clang
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A/lib/clang

因此,如果要构建针对旧的SDK(如MaxOSX10.15),请将CC设置为你需要的显式版本,例如:

CC=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A/lib/clang go build
英文:

You need to change the CC compile go uses during your builds.

 go env CC

 clang

which most likely uses the version in /usr/bin/clang

if you have Xcode installed - or really just the Command Line Tools you can see a variety of versions for the last few major releases e.g.:

$ find  /Library/Developer/CommandLineTools -name clang

/Library/Developer/CommandLineTools/usr/bin/clang
/Library/Developer/CommandLineTools/usr/lib/clang
/Library/Developer/CommandLineTools/usr/lib/swift/clang
/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/A/lib/clang
/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A/lib/clang
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/A/lib/clang
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A/lib/clang
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/A/lib/clang
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A/lib/clang

so to build against an older SDK like MaxOSX10.15, set CC to the explicit version you need for your go build like so:

CC=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A/lib/clang go build

答案2

得分: 0

我有很好的经验,可以将Unix可执行文件构建并打包为Mac应用程序,使用的是https://medium.com/@mattholt/packaging-a-go-application-for-macos-f7084b00f6b5上的说明手册。

构建Unix可执行文件:
go build -o bin/{program} {program}

在macOS(Big Sur)上打包应用程序并在macOS(High Sierra)上安装成功。

英文:

I have good experience building as a Unix executable and packaging as a Mac app, by using the instructions manual at
https://medium.com/@mattholt/packaging-a-go-application-for-macos-f7084b00f6b5

build Unix exec file
go build -o bin/{program} {program}

Packaging the application on macOS (Big Sur) and installing it on macOS (High Sierra) was successful.

huangapple
  • 本文由 发表于 2021年9月8日 02:11:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/69092823.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定