[英]Getting linking error: Some Makefile Issue
我正在嘗試將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 }
代碼文件:folder / func2.c
1 char* showMsg()
2 {
3 return "Hello World";
4 }
〜
〜
我覺得
char* showMsg()
在folder/func2.c
應該是
char* func2()
或者,改變
char* str = func2();
至
char* str = showMsg();
在hellofun.c
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.