在 OSX 中安装 GNU 汇编器
无论我如何努力谷歌,我似乎都找不到(相对)易于遵循的关于如何在 Mac 上安装 GNU 汇编器的说明。
我知道我可以使用 gcc -c
(Mac 上的 Apple Clang)来汇编 .s
/ .S
文件,但我想使用实际的 GNU Binutils as
。
No matter how hard I google, I can't seem to find a (relatively) easy-to-follow instruction on how to install the GNU Assembler on a mac.
I know I can use gcc -c
(Apple Clang on a Mac) to assemble .s
/ .S
files, but I want to use actual GNU Binutils as
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
yasm
适用于 Mac OSX(我从 Homebrew 获得),并且它有一个GNUas
语法解析器可以通过-pgas
启用(可能还需要添加-rgas
)。它不是 100% 完整,但它涵盖了几乎所有内容。它可以输出多种对象格式(如果需要交叉编译),在我看来这非常酷。您还可以使用-p nasm
来使用 NASM 语法(完全支持)(同样,-r nasm
可能是必要的)。对于死尸发布感到抱歉,但这是一个仍然相关的问题,我相信它需要一个可接受的答案。
yasm
works on Mac OSX (I got it from Homebrew), and it has a GNUas
syntax parser which can be enabled with-p gas
(it may be necessary to also add-r gas
). It is not 100% complete, but it covers mostly everything. It can output to a variety of object formats (if cross-compiling is necessary), and in my opinion it's pretty cool. You can also use NASM syntax (which is completely supported) using-p nasm
(again,-r nasm
may be necessary).Sorry about necroposting, but this is a still-relevant question and I believe that it needs an acceptable answer.
GNU 汇编器(尚)不能用于创建本机目标文件(Mach-O 格式)。但是,如果您想要的话,您当然可以使用它来交叉汇编某些非本机对象格式。
The GNU assembler cannot (yet) be used to create native object files (of Mach-O format). But you can of course use it to cross-assemble for some non-native object format, if that is what you want.
gnu 汇编器已安装在您的 Mac 上(假设您安装了开发工具包)。如果您想避免 XCode,可以使用
as
从命令行调用它,或者使用gcc yourfile.s $(OPTIONS)
通过预处理器调用它。编辑:
as
现在指向 clang 汇编器;在写这个答案时,它指向(Apple 的)GNU 汇编器。The gnu assembler is already installed on your mac (assuming that you installed the dev tools package). If you want to avoid XCode, you can invoke it from the command line with
as
, or with the preprocessor by usinggcc yourfile.s $(OPTIONS)
.Edit:
as
now points to the clang assembler; at the time this answer was written it pointed to (Apple's build of) the GNU assembler.也许
as
而不是gas
?如果你想让gas作为命令调用这个:echo "alias gas=as" > > $HOME/.profile
当我打开终端并输入它时,它就安装在我的 Mac Lion 上。这可能是因为 MacPorts 和/或 XCode,如之前答案的评论中提到的。
Maybe
as
instead ofgas
? If you want to have gas as command invoke this:echo "alias gas=as" >> $HOME/.profile
It was installed on my Mac Lion when i opened the terminal and typed it. It might have been because of MacPorts and/or XCode as mentioned in the comments of a previous answer.