作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个根目录和一个子目录。我计划将函数放在 libfunc.o
这个libfunc.o
应该与顶级目录中的其他目标文件合并。但我收到错误:
$make all
cd folder; make libfunc.o
make[1]: Entering directory `/home/Work/test_makefile/folder'
cc -c -o func2.o func2.c
cc -c -o func3.o func3.c
func3.c: In function ‘set’:
func3.c:3:25: warning: initialization makes pointer from integer without a cast [enabled by default]
ld -r -o libfunc.o func2.o func3.o
make[1]: Leaving directory `/home/Work/test_makefile/folder'
arm-linux-gnueabi-gcc -c -o hellofun.o hellofun.c -I. -I./include
arm-linux-gnueabi-gcc -c -o hellomake.o hellomake.c -I. -I./include
arm-linux-gnueabi-gcc hellofun.o hellomake.o folder/libfunc.o -o hm
folder/libfunc.o: file not recognized: File format not recognized
collect2: ld returned 1 exit status
make: *** [hm] Error 1
Makefile:顶层
1 CC=arm-linux-gnueabi-gcc
2 LD=arm-linux-gnueabi-ld
3 AR=arm-linux-gnueabi-ar
4 CFLAGS=-I. -I./include
5 SOURCES=hellofun.c hellomake.c
6 OBJECTS=$(SOURCES:.c=.o)
7 SUBDIR_OBJS=folder/libfunc.o
8 TARGET=hm
9 DEPS = hellomake.h
10
11 %.o: %.c $(DEPS) $(SUBDIR_OBJS)
12 $(CC) -c -o $@ $< $(CFLAGS)
13
14 folder/libfunc.o:
15 cd folder; $(MAKE) libfunc.o
16
17 clean:
18 rm -rf *.o hellomake folder/*.o
19
20 all: $(SOURCES) $(TARGET)
21
22 $(TARGET): $(OBJECTS)
23 $(CC) $(OBJECTS) $(SUBDIR_OBJS) -o $@
24
Makefile:子文件
1 SOURCES=$(wildcard *.c)
2 OBJECTS=$(SOURCES:.c=.o)
3 TARGET=libfunc.o
4 %.o: %.c
5 $(CC) -c -o $@ $< $(CFLAGS)
6
7 clean:
8 rm -rf *.o
9
10
11 $(TARGET): $(OBJECTS)
12 $(if $(strip $(OBJECTS)),\
13 $(LD) $(LDFLAGS) -r -o $@ $(OBJECTS),\
14 rm -f $@; $(AR) rcs $@ )
~
~
〜
最佳答案
这里有多个错误。首先,提问时请务必提供完整的错误消息。 norule to make target
错误将打印出它正在尝试创建的 which 目标;这是对您有帮助的关键信息。
其次,您引用了一个变量 SUBDIR_OBJS
,但该变量从未定义过。另外,您将其列为在 %.o : %.c
规则中构建其他目标文件的先决条件:将目标文件列为其他目标文件的先决条件实际上永远不会正确。
顶级 makefile 不会在 folder
目录中运行 make,因此该目录中的命令不会自动运行。您必须亲自去那里运行 make
。
此外,在config.mk
中,您创建了一个变量merge_object
,但在folder/Makefile
中,您引用了一个变量merge_objects
code>,这不是同一个变量。
关于c - 更新了 : How to invoke makefile of a child directory to create a consolidate . o 可链接的文件:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18863601/
我是一名优秀的程序员,十分优秀!