Using the GNU ToolChain to Run ARM/C on Windows Command Line

谁说我不能喝 提交于 2019-12-24 15:29:53

问题


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

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

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

> arm-none-eabi-as add2.s

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

Here's my code:

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 */
}

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)


回答1:


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)


来源:https://stackoverflow.com/questions/46571104/using-the-gnu-toolchain-to-run-arm-c-on-windows-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!