我正在尝试将 Makefiles 添加到我的嵌入式项目中,尝试创建一个小项目,但是在链接子目录中的文件时出现链接错误,请各位帮忙错误是:
arm-linux-gnueabi-gcc -c -o hellofun.o hellofun.c -I. -I./include
hellofun.c: In function ‘myPrintHelloMake’:
hellofun.c:6:14: warning: initialization makes pointer from integer without a cast [enabled by default]
hellofun.c:7:24: warning: initialization makes pointer from integer without a cast [enabled by default]
arm-linux-gnueabi-gcc -c -o hellomake.o hellomake.c -I. -I./include
arm-linux-gnueabi-gcc -c -o folder/func2.o folder/func2.c -I. -I./include
arm-linux-gnueabi-gcc hellofun.o hellomake.o folder/func2.o -o hm
hellofun.o: In function `myPrintHelloMake':
hellofun.c:(.text+0xc): undefined reference to `func2'
collect2: ld returned 1 exit status
make: *** [hm] Error 1
源文件 rootdir/Makefile:
1 CC=arm-linux-gnueabi-gcc
2 CFLAGS=-I. -I./include
3 SOURCES=hellofun.c hellomake.c
4 OBJECTS=$(SOURCES:.c=.o)
5 OBJECTS+=folder/func2.o
6 TARGET=hm
7 DEPS = hellomake.h
8
9 %.o: %.c $(DEPS)
10 $(CC) -c -o $@ $< $(CFLAGS)
11
12 clean:
13 rm -rf *.o hellomake folder/*.o
14
15 all: $(SOURCES) $(TARGET)
16
17 $(TARGET): $(OBJECTS)
18 $(CC) $(OBJECTS) -o $@
19
文件夹/Makefile:
1 SOURCES=$(wildcard *.c)
2 OBJECTS=$(SOURCES:.c=.o)
3 TARGET=func2.o
4 %.o: %.c
5 $(CC) -c -o $@ $< $(CFLAGS)
6
7 clean:
8 rm -rf *.o
9
10 $(TARGET): $(OBJECTS)
11
~
代码文件:hellomake.c
1 #include "hellomake.h"
2
3 int main()
4 {
5 myPrintHelloMake();
6 return 0;
7 }
代码文件:hellofun.c
1 #include "include/func2.h"
2
3 void myPrintHelloMake(void)
4 {
5 int i=0;
6 char* str = func2();
7 volatile char *addr = 0x80000000;
8
9 while(str[i]!='\0') {
10 addr[i] = str[i];
11 i++;
12 }
13
14 }
代码文件:文件夹/func2.c
1 char* showMsg()
2 {
3 return "Hello World";
4 }
~~
_