(avr-gcc) Makefile 对子目录的支持

发布于 2024-07-16 04:07:19 字数 564 浏览 4 评论 0原文

我正在开发一个 AVR 项目,并且有多个包含我的代码的文件夹。

我使用的 makefile 是 Pat Deegan 的“标准化 AVR Makefile 模板”。 它能够正确编译每个文件夹中的每个 cpp 文件并生成正确的目标 (.o) 文件。

但是,链接器失败,因为它尝试在子文件夹中查找 .o 文件(编译器将它们放在主文件夹中)。 这是我收到的错误的示例:

avr-gcc: 子文件夹/module.o: 没有这样的文件或目录 make: ***

[GrandCanyon.out] 错误 1

​​你能帮我修改它吗,以便链接器和编译器将文件 (.o) 放入并检查相同的文件夹?

谢谢

你可以在这里获取makefile: http://electrons.psychogenic.com/articles/Makefile .tpl

I am working on an AVR project and have multiple folders containing my code.

The makefile I am using is the "Standardized AVR Makefile Template" by Pat Deegan.
It's capable of compiling every cpp file in every folder correctly and generate the right object (.o) files.

However, the linker fails because it try to find to .o files in the subfolders (the compiler put them in the main folder).
This is an example of an error I get :

avr-gcc: subfolder/module.o: No such file or directory make: ***

[GrandCanyon.out] Error 1

Can you help me modifying it so the linker and compiler put and check for the files (.o) in the same folders?

Thank you

you can get the makefile here : http://electrons.psychogenic.com/articles/Makefile.tpl

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温暖的光 2024-07-23 04:07:19

问题是过滤器命令,它删除目录并仅保留文件名(链接)。 而不是在一行中定义所有文件并执行以下操作:

#  C
CFILES=$(filter %.c, $(PRJSRC))
#  Assembly
ASMFILES=$(filter %.S, $(PRJSRC))

因此,您需要手动定义每种类型的文件列表,

CCFILES = sub1/file1.c sub2/file2.c
ASMFILES = sub1/file1.asm sub3/file2.asm

The problem is the filter command, which removes the directory and leaves only the file name (link). So instead of defining all the files in a single line and doing:

#  C
CFILES=$(filter %.c, $(PRJSRC))
#  Assembly
ASMFILES=$(filter %.S, $(PRJSRC))

you need to manually define the file list for each type:

CCFILES = sub1/file1.c sub2/file2.c
ASMFILES = sub1/file1.asm sub3/file2.asm
随遇而安 2024-07-23 04:07:19

您好,我仅使用 C 语言而不是 C++ 来对 avr MCU 进行编程。 因此,我在 CFLAGS 部分中扩展了 makefile 大约一行,

CFLAGS=-I. $(INC) -g -mmcu=$(MCU) -O$(OPTLEVEL) \ 
    -fpack-struct -fshort-enums             \ 
    -funsigned-bitfields -funsigned-char    \ 
    -Wall -Wstrict-prototypes               \ 
    -o $(firstword $(filter %.o, $(<:.c=.o))) \
    -Wa,-ahlms=$(firstword $(filter %.lst, $(<:.c=.lst)))

当我在子目录中有源文件时,这对我有用。
我希望这会对您有所帮助,尽管这不适用于 C++

Hi I'm programming avr MCUs in C only not in C++. So I have extended makefile about one line in section CFLAGS

CFLAGS=-I. $(INC) -g -mmcu=$(MCU) -O$(OPTLEVEL) \ 
    -fpack-struct -fshort-enums             \ 
    -funsigned-bitfields -funsigned-char    \ 
    -Wall -Wstrict-prototypes               \ 
    -o $(firstword $(filter %.o, $(<:.c=.o))) \
    -Wa,-ahlms=$(firstword $(filter %.lst, $(<:.c=.lst)))

This works for me when I have source files in subdirectories.
I hope that this will help you althought that's not for C++

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文