如何在 Linux 上安装和使用 GAS (GNU Compiler)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4252012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 00:04:17  来源:igfitidea点击:

How to install and use GAS (GNU Compiler) on Linux?

linuxubuntuassemblygas

提问by rogcg

I'm using Ubuntu, and I was looking for an assembler compiler for Linux, and I found GAS.

我正在使用 Ubuntu,我正在寻找适用于 Linux 的汇编编译器,我找到了 GAS。

I'm trying to install it and run it, but I can't.

我正在尝试安装并运行它,但我不能。

采纳答案by wkl

asis the GNU Assembler. It's found in binutilsbut if you do:

asGNU 汇编器。它可以在binutils但如果你这样做:

sudo apt-get install build-essential

sudo apt-get install build-essential

You will get gasalong with gcc(which default uses gasfor assembling on the back end).

您将获得gasgcc(其默认用途gas用于装配在后端)。

For a 'tutorial' about using gas, you probably want to read Programming From the Ground Up, which uses it.

有关使用的“教程” gas,您可能想阅读使用它的编程从头开始。



To build a static executable from a .sfile,

要从文件构建静态可执行.s文件,

#!/bin/bash
f="${1:-}"
as "${f}" -o "${f%%.s}.o" && ld "${f%%.s}.0" -o "${f%%.s}"
gcc -nostdlib -static "${f}" -o "${f%%.s}"

If you want to link with libraries, it's normally easiest to let gcc use the right command line options for asand ldwhen building an executable from an asm source file.
gcc foo.s -o foowill work if your foo.sdefines a mainfunction.

如果你想与图书馆联系,这是最简单的,通常让GCC使用正确的命令行选项as,并ld从ASM源文件建立一个可执行文件时。
gcc foo.s -o foo如果您foo.s定义了一个main函数,它将起作用。

Also related: Assembling 32-bit binaries on a 64-bit system (GNU toolchain)if you're writing 32-bit programs on an x86-64 system.

还相关:如果您在 x86-64 系统上编写 32 位程序,则在 64 位系统(GNU 工具链)上组装 32 位二进制文​​件

回答by Ignacio Vazquez-Abrams

It's in the binutilspackage.

它在binutils包裹里。

回答by paxdiablo

Fire up Synaptic and enter "gnu assembler" into the quick search bar. It's immediately obvious that binutilsis the required package.

启动 Synaptic 并在快速搜索栏中输入“gnu assembler”。很明显,这binutils是必需的包。

And you may well find it's already installed. My binutils 2.20.1-3ubuntu7is already installed and I have a fairly vanilla set-up.

你可能会发现它已经安装了。我binutils 2.20.1-3ubuntu7的已经安装,我有一个相当普通的设置。

Entering as --versionfrom a terminal window will let you know:

as --version从终端窗口输入会让你知道:

GNU assembler (GNU Binutils for Ubuntu) 2.20.1-system.20100303
Copyright 2009 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `i486-linux-gnu'.

回答by BozoJoe

Have you read http://www.faqs.org/docs/Linux-HOWTO/Assembly-HOWTO.html? on Debian GAS is contained in the package

你读过http://www.faqs.org/docs/Linux-HOWTO/Assembly-HOWTO.html吗?Debian GAS 包含在包中

binutils

二进制实用程序

so

所以

sudo apt-get install binutils
dpkg -L binutils

$man as

$man as