使用 GNU ToolChain 在 Windows 命令行上运行 ARM/C [英] Using the GNU ToolChain to Run ARM/C on Windows Command Line

查看:38
本文介绍了使用 GNU ToolChain 在 Windows 命令行上运行 ARM/C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以前几天当我问了一个关于在 IDE 中运行此代码的类似问题时,您可能会认出我.最终我得到的建议是我应该学会从命令行一起运行它们.因此,我接受了建议并从 Codesourcery Lite MentorGraphics 安装了 GNU 工具链(不确定这是否有意义).我可以执行的命令是

so you might recognize me from the other day when I asked a similar question about running this code in an IDE. Eventually the advice I got was that I should learn to run them together from the command line. As such I took the advice and installed the GNU toolchain from Codesourcery Lite MentorGraphics (not sure if that makes sense). The commands I can do are things like

> arm-none-eabi-gcc -o main main.c -T script

但是,我无法确切地了解我应该如何使用这些命令.我试过了

However I'm having trouble finding out exactly how I am supposed to use the commands. I tried

> arm-none-eabi-gcc -o main (my c filename).c -T (my ARM filename).s

但是我从 ARM 文件中得到一个语法错误.然后我试着做

But I get a syntax error from that in the ARM file. I then tried to do

> arm-none-eabi-gcc -o main (my c filename).c

但是由于外部add2",这不起作用

But that doesn't work because of the external "add2"

> arm-none-eabi-as add2.s

这让我得到了一个文件a.out",但我不知道那是什么.

That gets me a file "a.out" but I don't know what that does.

这是我的代码:

手臂

    .global add2
add2:
    stmfd sp!, {v1-v6, lr}  @ 'standard' entry, save registers on the stack
    add a1, a1, a2          @ do the addition requested
    ldmfd sp!, {v1-v6, pc}

C

#include <stdio.h> /* standard input and output */
#include <stdlib.h> /* standard library */
extern int add2(int i, int j); /* tell the compiler that the routine is not defined here */
int main(int argc, char * argv[]) /* entry point to the program */
{
    int i, j; /* declare the variable types */
    int answer;
    i = 5; /* give the variables values */
    j = 20;
    answer = add2(i, j); /* call the assembly language routine */
    printf("result is : %d\n", answer); /* print out the answer */
    exit(0); /* leave the driver program */
}

任何帮助将不胜感激.我还在 Windows 上的 Ubuntu 上从 Bash 的 apt-get 安装了这个工具包,所以如果你有一个 BASH 解决方案也是可能的(https://packages.ubuntu.com/trusty/devel/gcc-arm-none-eabi)

Any help would be appreciated. I also installed this toolkit from apt-get from Bash on Ubuntu on Windows, so if you have a BASH solution that could also be possible (https://packages.ubuntu.com/trusty/devel/gcc-arm-none-eabi)

推荐答案

如果有人遇到过这种情况,我最终让它工作的方式是将这些脚本行输入到 Windows 命令行中:

In case anyone ever comes across this, the way I eventually got it working was to type these script lines into the Windows command-line:

Step 1: Compile your c-file
arm-none-eabi-gcc -o (object file name 1) -c (c file name)

Step 2: Assemble your ARM file
arm-none-eabi-gcc -o (object file name 2) -c (ARM file name)

Step 3: Link files and create executable
arm-none-eabi-gcc -o (executable file name) (object file name 1) (object 
file name 2) -T armulator-ram-hosted.ld

Step 4: Run the files
arm-none-eabi-run (executable file name)

这篇关于使用 GNU ToolChain 在 Windows 命令行上运行 ARM/C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆