从不同的子目录编译.c文件和.s文件

发布于 2024-09-15 07:12:19 字数 6181 浏览 5 评论 0原文

这是我的 makefile http://pastie.org/1104332。我正在尝试将不同子目录中的不同 .c 文件和 .s 文件(程序集文件)编译到 E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/ 然后链接器应该链接将构建目录 (E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680) 中的所有 .o 文件复制到名为 mfg-sample-app.out 的文件中。 当我运行上面发布的 makefile 时,编译器将所有源文件编译为构建目录中的目标文件,但链接器无法打开目标文件,因为它没有在构建目录(E:/em35x/)中查找它们构建/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680。我不知道为什么链接器看起来不在那里?这就是我得到的错误:(

E:\IARSystems\EmbeddedWorkbench5.4Evaluation\arm\bin\ilinkarm.exe"      -o E:/e
m35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample-app.out --
map E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample-ap
p.map --log initialization,modules,sections,veneers --log_file E:/em35x/build/mf
g-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample-app.log --config E:/em3
5x/app/mfglib/ewb-em357/../../../hal/micro/cortexm3/em35x/em357/iar-cfg.icf --di
ag_suppress Lp012 --entry halEntryPoint  E:/em35x/build/alarm-library-cortexm3-i
ar-em357-em3xx/alarm-library.a E:/em35x/build/binding-table-stub-library-cortexm
3-iar-em357-em3xx/binding-table-stub-library.a  E:/em35x/build/cbke-stub-library
-cortexm3-iar-em357-em3xx/cbke-stub-library.a E:/em35x/build/end-device-bind-stu
b-library-cortexm3-iar-em357-em3xx/end-device-bind-stub-library.a  E:/em35x/buil
d/hal-library-cortexm3-iar-em357-em3xx/hal-library.a E:/em35x/build/mfglib-libra
ry-cortexm3-iar-em357-em3xx/mfglib-library.a  E:/em35x/build/security-library-co
re-cortexm3-iar-em357-em3xx/security-library-core.a E:/em35x/build/security-libr
ary-link-keys-stub-cortexm3-iar-em357-em3xx/security-library-link-keys-stub.a E:
/em35x/build/zigbee-pro-stack-cortexm3-iar-em357-em3xx/zigbee-pro-stack.a E:/em3
5x/app/mfglib/mfg-sample.o E:/em35x/hal/ember-configuration.o E:/em35x/hal/micro
/cortexm3/adc.o E:/em35x/hal/micro/cortexm3/bootloader-interface-app.o E:/em35x/
hal/micro/cortexm3/bootloader-interface-standalone.o E:/em35x/hal/micro/cortexm3
/bootloader-interface.o E:/em35x/hal/micro/cortexm3/button.o E:/em35x/hal/micro/
cortexm3/buzzer.o E:/em35x/hal/micro/cortexm3/cstartup-iar-common.o E:/em35x/hal
/micro/cortexm3/diagnostic.o E:/em35x/hal/micro/cortexm3/led.o E:/em35x/hal/micr
o/cortexm3/mfg-token.o E:/em35x/hal/micro/cortexm3/micro-common.o E:/em35x/hal/m
icro/cortexm3/micro.o E:/em35x/hal/micro/cortexm3/sleep.o E:/em35x/hal/micro/cor
texm3/token-def.o E:/em35x/hal/micro/cortexm3/token.o E:/em35x/hal/micro/cortexm
3/uart.o E:/em35x/hal/micro/generic/crc.o E:/em35x/hal/micro/generic/endian.o E:
/em35x/hal/micro/generic/mem-util.o E:/em35x/hal/micro/generic/random.o E:/em35x
/hal/micro/generic/sim-eeprom.o E:/em35x/app/util/serial/cli.o E:/em35x/app/util
/serial/serial.o E:/em35x/hal/micro/cortexm3/em35x/mpu.o E:/em35x/hal/micro/cort
exm3/faults.o E:/em35x/hal/micro/cortexm3/isr-stubs.o

   IAR ELF Linker V5.50.5.51995/W32 for ARM
   Copyright (C) 2007-2010 IAR Systems AB.
Fatal error[Li001]: could not open file "E:\em35x\app\mfglib\mfg-sample.o"
Fatal error detected, aborting.
make: *** [mfg-sample-app.out] Error 3

首先它编译源文件,但最后它无法在构建文件夹中找到目标文件)

现在,在我从 makefile 中删除第 70 行之后

OBJ = $(SRC:.c=.o) E:/em35x/hal/micro/cortexm3/faults.o E:/em35x/hal/micro/cortexm3/isr-stubs.o

,链接器可以找到以前编译的目标文件在构建目录中并创建 .out 文件。如果我手动删除构建目录中的所有目标文件(编译器之前创建的)并再次运行 makefile(第 70 行仍然被删除),那么我会收到此错误:

$ make
make: *** No rule to make target `E:/em35x/build/mfg-sample-app-cortexm3-iar-em3
57-em3xx-dev0680/mfg-sample.o', needed by `mfg-sample-app.out'.  Stop.

如果我再次添加第 70 行,即:

OBJ = $(SRC:.c=.o) E:/em35x/hal/micro/cortexm3/faults.o E:/em35x/hal/micro/cortexm3/isr-stubs.o

那么它再次编译但不链接,因为它无法打开目标文件。 (再次提到第一个错误)

我不知道我做错了什么。我尝试了很多事情但找不到我的问题。

谢谢

编辑:我正在使用 GNU Make 3.81

已将倒数第二行更改为:

$(END_DIR)/%.o : %.c

并且我还按照 Gilles 的建议对 VPATH 进行了更改,但没有运气。

现在我得到这个错误:

$ make
make: *** No rule to make target `E:/em35x/build/mfg-sample-app-cortexm3-iar-em3
57-em3xx-dev0680/mfg-sample.o', needed by `mfg-sample-app.out'.  Stop.

它没有将任何 .c 文件编译成 .o 文件

编辑: Beta,我将能够在周一测试您的线路。然后我会报告结果,我想解决这个问题,它让我发疯。谢谢

编辑:

嗨 Beta,

我仍然收到与您建议的代码相同的错误。如果 mfg-sample.o 不在构建文件夹中(E:/em35x/build/mfg-sample-app-cortexm3-iar-em3 57-em3xx-dev0680) :

tjoyia@TJ-PC /e/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680
$ make
make: *** No rule to make target `E:/em35x/build/mfg-sample-app-cortexm3-iar-em3
57-em3xx-dev0680/mfg-sample.o', needed by `mfg-sample-app.out'.  Stop.

但是如果 mfg-sample.o 已存在于构建文件夹中(在我将 mfg-sample.c 编译为 mfg-sample.o 之后),那么我会收到此消息:

tjoyia@TJ-PC /e/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680
$ make
found E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample.
o, making mfg-sample-app.out

编辑:

嗨贝塔, 是的,这有效。

我收到这条消息:

tjoyia@TJ-PC /e/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680
$ make
found E:/em35x/app/mfglib/mfg-sample.c, making E:/em35x/build/mfg-sample-app-cor
texm3-iar-em357-em3xx-dev0680/mfg-sample.o
found E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample.
o, making mfg-sample-app.out

那么,我现在应该在原始 makefile 中做什么?我想编译整个项目并链接目标文件。(将不同路径位置中的所有 .c 文件链接到构建文件夹中,然后链接器应将先前创建的 .o 文件链接到 .out 文件中)

编辑:

嗨,Beta,

好吧,我已经开始工作了,但是两个 .s79 文件怎么样,我如何才能将它们编译到构建目录中的目标文件中呢?为什么 VPATH 不起作用,我认为我的依赖文件创建 (.d) 没有被调用,我如何才能调用它。我希望所有 .h 文件(源文件中的#include 语句)都能自动识别并依赖于目标文件。

之后我想转换 .out 文件,但它没有被调用。

问题是:

你知道如何将其添加到我的 makefile 中吗:

ielftool.exe --srec --verbose E:\em35x\build\mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680\mfg -sample-app.out E:\em35x\build\mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680\mfg-sample-app.s37

它应该将 mfg-sample-app.out 文件转换为从目标文件创建/链接 .out 文件后,mfg-sample-app.s37。

Here is my makefile http://pastie.org/1104332. I am trying to compile different .c files and .s files (assembly files) from different sub directories into E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/ then the linker should link all the .o files from the build directory (E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680) into a file named mfg-sample-app.out.
When I run the makefile which I posted above then the compiler compiles all the source files into object files in the build directory but the linker can not open the object files because its not looking for them in the build directory which is E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680. I dont know how why the linker does not look there? that is the error I get:

E:\IARSystems\EmbeddedWorkbench5.4Evaluation\arm\bin\ilinkarm.exe"      -o E:/e
m35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample-app.out --
map E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample-ap
p.map --log initialization,modules,sections,veneers --log_file E:/em35x/build/mf
g-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample-app.log --config E:/em3
5x/app/mfglib/ewb-em357/../../../hal/micro/cortexm3/em35x/em357/iar-cfg.icf --di
ag_suppress Lp012 --entry halEntryPoint  E:/em35x/build/alarm-library-cortexm3-i
ar-em357-em3xx/alarm-library.a E:/em35x/build/binding-table-stub-library-cortexm
3-iar-em357-em3xx/binding-table-stub-library.a  E:/em35x/build/cbke-stub-library
-cortexm3-iar-em357-em3xx/cbke-stub-library.a E:/em35x/build/end-device-bind-stu
b-library-cortexm3-iar-em357-em3xx/end-device-bind-stub-library.a  E:/em35x/buil
d/hal-library-cortexm3-iar-em357-em3xx/hal-library.a E:/em35x/build/mfglib-libra
ry-cortexm3-iar-em357-em3xx/mfglib-library.a  E:/em35x/build/security-library-co
re-cortexm3-iar-em357-em3xx/security-library-core.a E:/em35x/build/security-libr
ary-link-keys-stub-cortexm3-iar-em357-em3xx/security-library-link-keys-stub.a E:
/em35x/build/zigbee-pro-stack-cortexm3-iar-em357-em3xx/zigbee-pro-stack.a E:/em3
5x/app/mfglib/mfg-sample.o E:/em35x/hal/ember-configuration.o E:/em35x/hal/micro
/cortexm3/adc.o E:/em35x/hal/micro/cortexm3/bootloader-interface-app.o E:/em35x/
hal/micro/cortexm3/bootloader-interface-standalone.o E:/em35x/hal/micro/cortexm3
/bootloader-interface.o E:/em35x/hal/micro/cortexm3/button.o E:/em35x/hal/micro/
cortexm3/buzzer.o E:/em35x/hal/micro/cortexm3/cstartup-iar-common.o E:/em35x/hal
/micro/cortexm3/diagnostic.o E:/em35x/hal/micro/cortexm3/led.o E:/em35x/hal/micr
o/cortexm3/mfg-token.o E:/em35x/hal/micro/cortexm3/micro-common.o E:/em35x/hal/m
icro/cortexm3/micro.o E:/em35x/hal/micro/cortexm3/sleep.o E:/em35x/hal/micro/cor
texm3/token-def.o E:/em35x/hal/micro/cortexm3/token.o E:/em35x/hal/micro/cortexm
3/uart.o E:/em35x/hal/micro/generic/crc.o E:/em35x/hal/micro/generic/endian.o E:
/em35x/hal/micro/generic/mem-util.o E:/em35x/hal/micro/generic/random.o E:/em35x
/hal/micro/generic/sim-eeprom.o E:/em35x/app/util/serial/cli.o E:/em35x/app/util
/serial/serial.o E:/em35x/hal/micro/cortexm3/em35x/mpu.o E:/em35x/hal/micro/cort
exm3/faults.o E:/em35x/hal/micro/cortexm3/isr-stubs.o

   IAR ELF Linker V5.50.5.51995/W32 for ARM
   Copyright (C) 2007-2010 IAR Systems AB.
Fatal error[Li001]: could not open file "E:\em35x\app\mfglib\mfg-sample.o"
Fatal error detected, aborting.
make: *** [mfg-sample-app.out] Error 3

(first it compiles the source files but at the end it cannot find the object files in the build folder)

Now after I delete line 70 from the makefile which is

OBJ = $(SRC:.c=.o) E:/em35x/hal/micro/cortexm3/faults.o E:/em35x/hal/micro/cortexm3/isr-stubs.o

then the linker can find the previous compiled object files in the build directory and creates the .out file. And if I manually delete all the object files from the build directory (which the compiler created previously) and run the makefile again (line 70 is still deleted) then I get this error:

$ make
make: *** No rule to make target `E:/em35x/build/mfg-sample-app-cortexm3-iar-em3
57-em3xx-dev0680/mfg-sample.o', needed by `mfg-sample-app.out'.  Stop.

And if I add line 70 again which is :

OBJ = $(SRC:.c=.o) E:/em35x/hal/micro/cortexm3/faults.o E:/em35x/hal/micro/cortexm3/isr-stubs.o

then it compiles again but does not link because it cannot open the object files. (The first mentioned error again)

I dont know what I am doing wrong. I have tried many things but cannot find my problem.

Thanks

EDIT: I am using GNU Make 3.81

have changed the second-to-last line to:

$(END_DIR)/%.o : %.c

and I also made changes to VPATH as suggested by Gilles but no luck.

Now I get this erorr:

$ make
make: *** No rule to make target `E:/em35x/build/mfg-sample-app-cortexm3-iar-em3
57-em3xx-dev0680/mfg-sample.o', needed by `mfg-sample-app.out'.  Stop.

It is not compiling any .c file into a .o file

EDIT: Beta, I will be able to test you lines on Monday. I will then report the results, I want to resolve this issue it is driving me crazy. Thanks

EDIT:

Hi Beta,

I am still getting the same error with the code you suggested. This is the error, if mfg-sample.o is not in the build folder (E:/em35x/build/mfg-sample-app-cortexm3-iar-em3
57-em3xx-dev0680) :

tjoyia@TJ-PC /e/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680
$ make
make: *** No rule to make target `E:/em35x/build/mfg-sample-app-cortexm3-iar-em3
57-em3xx-dev0680/mfg-sample.o', needed by `mfg-sample-app.out'.  Stop.

But if mfg-sample.o already exists in the build folder (after I complied mfg-sample.c to mfg-sample.o) then I get this message:

tjoyia@TJ-PC /e/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680
$ make
found E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample.
o, making mfg-sample-app.out

EDIT:

Hi Beta,
Yes, that worked.

I got this message:

tjoyia@TJ-PC /e/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680
$ make
found E:/em35x/app/mfglib/mfg-sample.c, making E:/em35x/build/mfg-sample-app-cor
texm3-iar-em357-em3xx-dev0680/mfg-sample.o
found E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/mfg-sample.
o, making mfg-sample-app.out

So, what should I do now in my original makefile? I want to compile my whole project and link the object files.(all my .c files in different path locations into the build folder and then the linker should link the previous created .o files into the .out file)

EDIT:

Hi Beta,

Ok I got it working, but what about the two .s79 files how I can get them also compiled into object files in the build directory? Why is VPATH not working and I think my dependcy file creation (.d) is not invoked how I can get the invoked. I want all the .h files (#include statements in the source files) get automatically recognized and depend on the object file.

And after that I want to convert the .out files but its not getting invoked.

Here is the problem:

Do you know how I could add this to my makefile:

ielftool.exe --srec --verbose E:\em35x\build\mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680\mfg-sample-app.out E:\em35x\build\mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680\mfg-sample-app.s37

It should convert the mfg-sample-app.out file into a mfg-sample-app.s37 after the .out file is created/linked from the object files.

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

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

发布评论

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

评论(3

可是我不能没有你 2024-09-22 07:12:19

首先,该链接并不指向 makefile,它指向您尝试运行 make 的输出。其次,我没有看到任何证据表明它确实生成了 mfg-sample-app.o,但你说它确实生成了,所以我相信你的话。

有几个不同的原因可能导致此错误。我建议您恢复第 70 行,从头开始并运行 make 两次。我认为它很有可能在第一次传递时构建目标文件并在第二次传递时找到它们。无论它做什么,我们都会学到一些东西。 (我建议您也更改为更有信誉的编译器/链接器,例如 gcc,但它看起来好像以非标准方式使用了一些标志。)

您遇到的第二个错误很容易理解:您删除了行定义了对象列表,并且规则是根据该列表定义的,因此 Make 不再知道如何构建这些对象。但让我害怕的是 Make 知道如何在没有该列表的情况下调用链接器;它表明你的 makefile 有很多冗余,这是不好的。

顺便问一下,您使用的是什么品牌?尝试运行make -v并查看它的内容。

编辑:
现在我可以查看 makefile,我想我可以解开这个谜团了。

有问题的源文件是 E:/em35x/app/mfglib/mfg-sample.c。第 70 行就位后,Make 只需将 .c 更改为 .o 并得出结论,有问题的目标文件是 E:/em35x/app/mfglib/mfg -sample.o。但是您已将构建目录路径硬编码到编译器标志中(这是非常不好的做法),因此这就是对象文件所在的位置。然后,当 Make 到达链接步骤时,它找不到 E:/em35x/app/mfglib/mfg-sample.o,然后就死掉了。

当您在没有第 70 行的情况下运行时,它会使用前面的行并得出结论:mfg-sample.o 应该位于构建目录中。如果该目标文件在运行之前已经存在,则 Make 将目标文件链接在一起,一切顺利。但是,如果该文件不存在,则 Make 无法构建它,因为此 makefile 只知道构建目标文件的一种方法,即通过编译源代码,该源代码位于其打算构建对象的同一目录中< /em>。由于build目录下没有这样的源文件,所以就死掉了。

这个 makefile 可能需要做很多工作,但这是(可能)解决您的问题的最小更改。 (你还没有说你使用的是哪个版本的 Make——这适用于 GNUMake。)去掉第 70 行并修改倒数第二行:

$(END_DIR)/%.o : %.c

现在,无论 Make 认为目标文件应该放在哪里,它都会查找不带路径的源文件 (mfg-sample.c),VPATH 会找到它。

PS Gilles 指出 VPATH 中的分隔符在 Windows 中可能不起作用。如果我建议的更改不起作用,请尝试按照吉尔斯的建议更改分隔符(单独更改分隔符没有帮助)。

编辑:
VPATH 似乎不起作用。我们可以没有它,但我想在放弃它之前尝试最后一次实验。请尝试此操作并告诉我们会发生什么:

END_DIR = E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680

OBJ = $(END_DIR)/mfg-sample.o 

VPATH = E:/em35x/app/mfglib

mfg-sample-app.out : $(OBJ)
  @echo found 
lt;, making $@

$(END_DIR)/%.o : %.c
  @echo found 
lt;, making $@
  @touch $@

编辑 3:
好吧,VPATH 不起作用——也许稍后我们可以找出原因。

试试这个(可能有用,也可能不行——我很难测试 Windows 风格的路径):

END_DIR = E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680

OBJ = $(END_DIR)/mfg-sample.o 

mfg-sample-app.out : $(OBJ)
  @echo found 
lt;, making $@

$(END_DIR)/mfg-sample.o : E:/em35x/app/mfglib/mfg-sample.c

$(END_DIR)/%.o :
  @echo found 
lt;, making $@
  @touch $@

编辑 4:

交叉手指并尝试将其拼接到真正的 makefile 中(并去掉第 70 行):

$(END_DIR)/mfg-sample.o: E:/em35x/app/mfglib/mfg-sample.c

$(END_DIR)/ember-configuration.o: E:/em35x/hal/ember-configuration.c

CORTEXM3 = adc \
bootloader-interface-app \
bootloader-interface-standalone \
bootloader-interface \
button \
buzzer \
cstartup-iar-common \
diagnostic \
led \
mfg-token \
micro-common \
micro \
sleep \
token-def \
token \
uart

CORTEXM3_OBJS = $(patsubst %,$(END_DIR)/%.o,$(CORTEXM3))
$(CORTEXM3_OBJS): $(END_DIR)/%.o : E:/em35x/hal/micro/cortexm3/%.c

GENERIC = crc \
endian \
mem-util \
random \
sim-eeprom

GENERIC_OBJS = $(patsubst %,$(END_DIR)/%.o,$(GENERIC))
$(GENERIC_OBJS): $(END_DIR)/%.o : E:/em35x/hal/micro/generic/%.c

$(END_DIR)/cli.o $(END_DIR)/serial.o: $(END_DIR)/%.o : E:/em35x/app/util/serial/%.c

$(END_DIR)/mpu.o: E:/em35x/hal/micro/cortexm3/em35x/mpu.c

$(END_DIR)/%.o :
    $(CC) $(CFLAGS) $(INCLUDES) 
lt;

看看为什么 VPATH 如此方便?

编辑5:

  • s79 文件:

    我们更改规则(编辑 4 的最后两行):

    # 更改此内容:
    #
    # $(END_DIR)/%.o :
    # $(CC) $(CFLAGS) $(INCLUDES) 
    lt;
    
    # 对此:
    
    $(END_DIR)/mfg-sample.o \
    $(END_DIR)/ember-configuration.o \
    $(CORTEXM3_OBJS) \
    $(GENERIC_OBJS) \
    $(END_DIR)/cli.o $(END_DIR)/serial.o \
    $(END_DIR)/mpu.o:
        $(CC) $(CFLAGS) $(包括) 
    lt;
    

    (如果您愿意,您可以将这些目标放在一行上,我是为了提高可读性。)

    验证这是否有效,然后为 s79 源添加另一个规则:

    $(END_DIR)/faults.o $(END_DIR)/isr-stubs.o : $(END_DIR)/%.o : E:/em35x/hal/micro/cortexm3/%.s79
        @echo 尝试从 
    lt; 构建 $@
        $(ASM) $(AFLAG) $(AFLAG1) $(AFLAG2) $(AFLAG3) $(AFLAG4) 
    lt;
    

    并确保将这两个附加到 OBJ 变量中,以便 Make 知道 mfg-sample-app.out 需要什么。

  • VPATH。我不知道为什么 VPATH 不起作用。可以进行更多调查,但像这样远程进行是非常困难的。您可以尝试一下:在我建议的实验性 makefile 中(在第二个编辑块中)将 VPATH 行更改为:

    vpath %.c E:/em35x/app/mfglib
    

    (注意小写。)

  • 依赖文件 (.d)。 我不知道规则中的命令是否有效(我无权访问您的“嵌入式工作台”工具),但规则无效的原因被调用的原因是 include 语句使用了未定义的变量 (sources)。 Make 无法以这种方式找到任何源文件,因此它认为它不必包含任何内容,因此它认为它不必构建任何内容(即使它想也不能构建任何东西,因为它找不到来源)。您可以改用 SRC 变量,但不要忘记添加到 s79 文件中。

  • 转换 .out 文件。 小菜一碟:

    E:\em35x\build\mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680\mfg-sample-app.s37 : mfg-sample-app.out
        ielftool.exe --srec --verbose 
    lt; $@
    

    (如果您希望这是默认目标,请将其放在所有其他目标之前。)我硬编码了 s37 目标的路径,因为您指定了它。您可能只需使用 mfg-sample-app.s37 即可。

  • First, that link doesn't point to a makefile, it points to the output of your attempt to run make. Second, I don't see evidence there that it actually produced mfg-sample-app.o, but you say it did so I'll take your word for it.

    There are a couple of different things that could be causing this error. I suggest you restore line 70, start from a clean slate and run make twice. I think there's a good chance it'll build the object files on the first pass and find them on the second. And no matter what it does, we'll learn something. (I'd suggest you also change to a more reputable compiler/linker, like gcc, but it looks as if this one uses some flags in a non-standard way.)

    The second error you got is easy to understand: you deleted the line that defined a list of objects, and a rule was defined in terms of that list, so Make didn't know how to build those objects any more. But it scares me that Make knew how to invoke the linker without that list; it suggests that your makefile has a lot of redundancy in it, which is bad.

    By the way, what make are you using? Try running make -v and see what it says.

    EDIT:
    Now that I can look at the makefile, I think I can clear up this mystery.

    The source file in question is E:/em35x/app/mfglib/mfg-sample.c. With line 70 in place, Make just changes .c to .o and concludes that the object file in question is E:/em35x/app/mfglib/mfg-sample.o. But you've hard-coded the build directory path into the compiler flags (a very bad practice), so that's where the objects files go. Then when Make gets to the linking step it can't find E:/em35x/app/mfglib/mfg-sample.o, and dies.

    When you run without line 70, it uses the earlier line and concludes that mfg-sample.o should be in the build directory. If that object file is already there before you run, Make links the object files together and all is well. But if the file is not there, then Make cannot build it, because this makefile knows only one way to build an object file and that is by compiling source code that is in the same directory where it intends to build the object. Since there is no such source file in the build directory, it dies.

    This makefile could use a lot of work, but here's the smallest change that will (probably) solve your problem. (You haven't said what version of Make you use-- this works for GNUMake.) Get rid of line 70 and modify the second-to-last line:

    $(END_DIR)/%.o : %.c
    

    Now, no matter where Make thinks the object file should go, it will look for the source file without the path (mfg-sample.c) and VPATH will find it.

    P.S. Gilles has pointed out that the delimiter in VPATH may not work in Windows. If the change I suggest doesn't work, try also changing the delimiter as Gilles suggests (changing the delimiter alone won't help).

    EDIT:
    VPATH doesn't seem to be working. We can do without it, but I'd like to try one last experiment before we abandon it. Please try this and tell us what happens:

    END_DIR = E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680
    
    OBJ = $(END_DIR)/mfg-sample.o 
    
    VPATH = E:/em35x/app/mfglib
    
    mfg-sample-app.out : $(OBJ)
      @echo found 
    lt;, making $@
    
    $(END_DIR)/%.o : %.c
      @echo found 
    lt;, making $@
      @touch $@
    

    EDIT 3:
    All right, VPATH isn't working-- maybe later we can figure out why.

    Try this (it might work, it might not-- it's hard for me to test the Windows-style paths):

    END_DIR = E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680
    
    OBJ = $(END_DIR)/mfg-sample.o 
    
    mfg-sample-app.out : $(OBJ)
      @echo found 
    lt;, making $@
    
    $(END_DIR)/mfg-sample.o : E:/em35x/app/mfglib/mfg-sample.c
    
    $(END_DIR)/%.o :
      @echo found 
    lt;, making $@
      @touch $@
    

    EDIT 4:

    Cross your fingers and try splicing this into your real makefile (and get rid of line 70):

    $(END_DIR)/mfg-sample.o: E:/em35x/app/mfglib/mfg-sample.c
    
    $(END_DIR)/ember-configuration.o: E:/em35x/hal/ember-configuration.c
    
    CORTEXM3 = adc \
    bootloader-interface-app \
    bootloader-interface-standalone \
    bootloader-interface \
    button \
    buzzer \
    cstartup-iar-common \
    diagnostic \
    led \
    mfg-token \
    micro-common \
    micro \
    sleep \
    token-def \
    token \
    uart
    
    CORTEXM3_OBJS = $(patsubst %,$(END_DIR)/%.o,$(CORTEXM3))
    $(CORTEXM3_OBJS): $(END_DIR)/%.o : E:/em35x/hal/micro/cortexm3/%.c
    
    GENERIC = crc \
    endian \
    mem-util \
    random \
    sim-eeprom
    
    GENERIC_OBJS = $(patsubst %,$(END_DIR)/%.o,$(GENERIC))
    $(GENERIC_OBJS): $(END_DIR)/%.o : E:/em35x/hal/micro/generic/%.c
    
    $(END_DIR)/cli.o $(END_DIR)/serial.o: $(END_DIR)/%.o : E:/em35x/app/util/serial/%.c
    
    $(END_DIR)/mpu.o: E:/em35x/hal/micro/cortexm3/em35x/mpu.c
    
    $(END_DIR)/%.o :
        $(CC) $(CFLAGS) $(INCLUDES) 
    lt;
    

    See why VPATH is so handy?

    EDIT 5:

  • The s79 files:

    We change the rule (the last two lines of EDIT 4):

    # change this:
    #
    # $(END_DIR)/%.o :
    #    $(CC) $(CFLAGS) $(INCLUDES) 
    lt;
    
    # to this:
    
    $(END_DIR)/mfg-sample.o \
    $(END_DIR)/ember-configuration.o \
    $(CORTEXM3_OBJS) \
    $(GENERIC_OBJS) \
    $(END_DIR)/cli.o $(END_DIR)/serial.o \
    $(END_DIR)/mpu.o:
        $(CC) $(CFLAGS) $(INCLUDES) 
    lt;
    

    (You can put those targets on one line if you like, I was going for readability.)

    Verify that this works, then put in another rule for the s79 sources:

    $(END_DIR)/faults.o $(END_DIR)/isr-stubs.o : $(END_DIR)/%.o : E:/em35x/hal/micro/cortexm3/%.s79
        @echo attempting to build $@ from 
    lt;
        $(ASM) $(AFLAG) $(AFLAG1) $(AFLAG2) $(AFLAG3) $(AFLAG4) 
    lt;
    

    And be sure to append those two to the OBJ variable, so that Make will know what mfg-sample-app.out needs.

  • VPATH. I don't know why VPATH isn't working. More investigation is possible, but it's very difficult to do remotely like this. You can try a long shot: in the experimental makefile I suggested (in the second EDIT block) change the VPATH line to this:

    vpath %.c E:/em35x/app/mfglib
    

    (Note the lower case.)

  • Dependency files (.d). I don't know whether the commands in the rules work (I don't have access to your "Embedded Workbench" tools), but the reason the rules aren't being invoked is that the include statements use a variable (sources) which is undefined. Make can't find any source files that way, so it doesn't think it has to include anything, so it doesn't think it has to build anything (and couldn't even if it wanted to because it can't find the sources). You can use the SRC variable instead, but don't forget to add in the s79 files.

  • Converting the .out files. Piece of cake:

    E:\em35x\build\mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680\mfg-sample-app.s37 : mfg-sample-app.out
        ielftool.exe --srec --verbose 
    lt; $@
    

    (If you want this to be your default target, put it before all others.) I hard-coded the path to the s37 target because you specified it. You could probably do with just mfg-sample-app.s37.

  • 梦里泪两行 2024-09-22 07:12:19

    OBJ 有两个定义。明确列出所有对象并表示它们位于 END_DIR 中,但没有规则可以从不同目录中的源文件在一个位置构建对象文件。第二条规则使用源文件并将 .c 替换为 .o(目标文件将与源文件位于同一目录中)。

    删除第二条规则后,make 使用第一个定义来标识目标文件应该用于链接的位置,但不知道如何生成它们。这解释了第二个错误。要修复此问题,请修改编译规则以将目标文件放置在不同的目录中,或者使用第 70 行上的规则,该规则表明它们与源文件位于同一位置。

    目前尚不清楚为什么第一遍不起作用,但我建议在编译工作之前取消依赖文件 (.d) 的生成和包含。我发现将它们作为编译的副作用来构建比显式创建它们要有用得多。如果它们不存在,那么您还没有编译任何东西,无论如何都必须进行完整的构建。

    You have two definitions of OBJ. One explicitly lists all of the objects and says they are in the END_DIR, but there's no rule to build an object file in one place from a source file in a different directory. The second rule uses the source files and replaces .c with .o (and the object files would be in the same directory as the source).

    After you deleted the second rule, make used the first definition to identify where the object files should be for linking, but didn't know how to generate them. This explains the second error. To fix it, either modify the compilation rule to place the object files in a different directory, or use use the rule on line 70 that says they are in the same place as the source.

    It's not clear why the first pass didn't work, but I'd recommend taking out the generation and inclusion of the dependence files (.d) until the compilation is working. I've found that it's far more useful to build them as a side effect of compilation than to create them explicitly. If they don't exist, then you haven't compiled anything and have to do a complete build anyway.

    孤者何惧 2024-09-22 07:12:19

    链接器完全按照它的指示进行操作:它被告知要链接“E:\em35x\app\mfglib\mfg-sample.o”,但它不存在。

    makefile 中 VPATH 的定义有问题:: 既用作 DOS/Windows 驱动器指示符,又用作路径分隔符。在 Windows 上,您必须将 : 替换为 ; 或空格。 (这可能会破坏与 make 的其他 unix 实现的兼容性,这可能就是生成此(部分)makefile 的脚本的作者使用 : 的原因。)

    VPATH = E:/em35x/app/mfglib/ E:/em35x/hal/ E:/em35x/hal/micro/cortexm3/ E:/em35x/hal/micro/generic/ E:/em35x/app/util/serial/ E:/em35x/hal/micro/cortexm3/ E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/
    

    The linker is doing exactly what it's told: it's told to link "E:\em35x\app\mfglib\mfg-sample.o", which doesn't exist.

    There is a problem in the definition of VPATH in the makefile: : is used both as the DOS/Windows drive indicator and as the path separator. On Windows, you must replace : by ; or by blanks. (This might break compatibility with other unix implementations of make, which is probably why the author of the script that generated this (part of the) makefile used :.)

    VPATH = E:/em35x/app/mfglib/ E:/em35x/hal/ E:/em35x/hal/micro/cortexm3/ E:/em35x/hal/micro/generic/ E:/em35x/app/util/serial/ E:/em35x/hal/micro/cortexm3/ E:/em35x/build/mfg-sample-app-cortexm3-iar-em357-em3xx-dev0680/
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文