drw85135
2015-01-15 05:01
浏览 337
已采纳

Go编译文件如何在不同的OS或CPU架构上工作?

Since I have started to learn Golang since yesterday :) I have a question about the compiled file.

Let's assume that I compile my project. It generates an .exec file in /bin folder. Now my question is Since the file has been compiled on Mac with Intel based CPU, should it be compiled on other OS and other CPU architectures such as AMD, ARM, etc. if I want to publish it to public?

I guess this should not be problem if I'm using GO lang for my backend since I run it on a server. However, what happens if I publish my .exec file, let's say on AWS, with lots of instances that they are automatically increases/decreases based on load? Does it problem?

Edit:

This is nice solution for those how are looking Go cross compiling tool https://github.com/mitchellh/gox

图片转代码服务由CSDN问答提供 功能建议

自从昨天开始学习Golang以来:)我对编译后的文件有疑问。

假设我编译了我的项目。 它在/ bin文件夹中生成一个.exec文件。 现在我的问题是,由于该文件已经在Mac上使用基于Intel的CPU进行编译,如果我想公开发布该文件,是否应该在其他OS和其他CPU体系结构(例如AMD,ARM等)上进行编译?

我想如果我在后端使用GO lang作为后端,那应该不会有问题,因为我是在服务器上运行它的。 但是,如果我发布.exec文件(比如说在AWS上),并且有很多实例会根据负载自动增加/减少,那会发生什么呢? 会不会有问题?

编辑

对于那些看起来像Go交叉编译工具 https://github.com/mitchellh/gox

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtrn74832 2015-01-15 05:12
    已采纳

    The answer to the first question is yes. The current implementations of Go produce a native binary, so you will probably need a different one for Linux x86 (32-bit), Linux x64 (64-bit), and Linux ARM. You will probably need a different one for Mac OS X also. You should be able to run the 32-bit executable on a 64-bit system as long as any libraries you depend on are available in 32-bit form on that system, so you might be able to skip making a 64-bit executable.

    In the future, there may be other implementations of Go that compile for a virtual machine (such as JVM or .NET), in which case you wouldn't need to compile multiple versions for different architectures. Your question is more about existing Go implementations than the language itself.

    I don't know anything about AWS, but I suggest you ask that as a separate question.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题