编译具有汇编程序文件依赖项的C文件 [英] Compiling C File with Assembler file dependencies

查看:109
本文介绍了编译具有汇编程序文件依赖项的C文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件app.c,它可以调用两个外部函数,即. func_asm1和func_asm2.这两个函数都在单独的汇编器文件中,即. func_asm1.S和func_asm2.S.此外, 我有两个头文件,即. func_asm1.h和func_asm2.h,其中定义了两个汇编器函数的接口:

I have a file app.c that makes calls to two external functions, ie. func_asm1 and func_asm2. Both functions are in a seperate Assembler file, ie. func_asm1.S and func_asm2.S. Furthermore, I have two header files, ie. func_asm1.h and func_asm2.h where the interface of the two assembler functions are defined:

extern void func_asm1(unsigned int *r, const unsigned int *a);

主文件app.c包含两个头文件func_asm1.h和func_asm2.h,这是我的make文件 如下所示,但我无法正常工作...任何人都知道什么地方可能出问题了?

The main file app.c includes the two header func_asm1.h and func_asm2.h, my make file looks at the moment as follows but I does not work... Anyone an idea what could be wrong?

CC  = bin/arm-elf-gcc
AS  = bin/arm-elf-as
SFLAGS=-S -O2

func_asm1.o: func_asm1.S
    $(AS) -o $@ $< 

func_asm2.o: func_asm2.S
    $(AS) -o $@ $<

app.o: app.c app.h func_asm1.h func_asm2.h
    $(CC) $(SFLAGS) app.c -o app.o func_asm1.o func_asm2.o

非常感谢您的帮助!

推荐答案

我认为您的makefile具有错误的依赖项:

I think your makefile has wrong dependencies:

最后一部分应该是这样的:

The last part should be something like:

func_asm1.o: func_asm1.S
$(AS) -o $@ $< 

func_asm2.o: func_asm2.S
$(AS) -o $@ $<

app: app.c app.h func_asm1.h func_asm2.h func_asm1.o func_asm2.o
$(CC) $(SFLAGS) app.c -o app.o func_asm1.o func_asm2.o

为什么?因为func_asm1.o和func2.o取决于它们的源代码(我假设您未在汇编器源代码中使用func_asm.h) 另一方面,app.o取决于其源代码(app.c),其头文件(app.h,func_asm1.h和func_asm2.h)以及汇编文件的目标代码.请注意,您正在编译makefile的该部分中的 AND 链接,因此,如果汇编文件的目标代码发生更改,则必须重新链接应用程序并因此执行这些行.

Why ? Because func_asm1.o and func2.o depends their source code (I am assuming that you don't use func_asm.h in the assembler source code) On the other hand, app.o depends on its source code (app.c), its header files (app.h, func_asm1.h and func_asm2.h) and the object code for the assembly files. Note that you are compiling AND linking in that part of the makefile so if the object code for the assembly files change, you have to relink the application and therefore execute those lines.

正如我在评论中指出的那样,您应该检查传递给gcc的参数(SFLAGS中传递的-S标志)

As I've been pointed out in the comments, you should check the parameters passed to gcc (the -S flag passed in SFLAGS )

这篇关于编译具有汇编程序文件依赖项的C文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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