【问题标题】:Using the GNU ToolChain to Run ARM/C on Windows Command Line使用 GNU ToolChain 在 Windows 命令行上运行 ARM/C
【发布时间】:2018-03-16 05:10:38
【问题描述】:

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

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

但是,我无法准确找出我应该如何使用这些命令。我试过了

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

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

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

但这不起作用,因为外部“add2”

> arm-none-eabi-as add2.s

这给我一个文件“a.out”,但我不知道它是做什么的。

这是我的代码:

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 解决方案也是可能的 (https://packages.ubuntu.com/trusty/devel/gcc-arm-none-eabi)

【问题讨论】:

  • 你遇到了什么错误?
  • 对于哪个命令?
  • 对于你得到的每个命令。
  • D:\Joe\College Stuff\CS 252\Homework&gt;arm-none-eabi-gcc -o main addDrive.c -T add21.s d:/mentorgraphics/sourcery_codebench_lite_for_arm_eabi/bin/../lib/gcc/arm-none-eabi/4.8.3/../../../../arm-none-eabi/bin/ld.exe:add21.s:1: syntax error collect2.exe: error: ld returned 1 exit status 第一个命令 C:\Users\Joe\AppData\Local\Temp\ccw6rCCg.o: In function main': addDrive.c:(.text+0x2c): undefined reference to add2' 第二个命令
  • -T 用于链接描述文件,而不用于汇编输入。

标签: c bash command-line arm gnu-toolchain


【解决方案1】:

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

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-07
    • 1970-01-01
    • 2021-05-17
    • 2012-03-21
    • 2021-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多