使用GNU ToolChain在Windows命令行上运行ARM/C [英] Using the GNU ToolChain to Run ARM/C on Windows Command Line
问题描述
所以从前几天我问一个关于在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.
这是我的代码:
ARM
.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解决方案(
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屋!