gpt4 book ai didi

c - 出现链接错误 : Some Makefile Issue

转载 作者:行者123 更新时间:2023-11-30 17:47:41 27 4
gpt4 key购买 nike

我正在尝试将 Makefile 添加到我的嵌入式项目中,已尝试创建一个小项目,但在链接子目录中的文件时出现链接错误,你们能帮忙吗错误是:

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

源文件根目录/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 }

~

最佳答案

我认为

char* showMsg()

folder/func2.c中应该是

char* func2()

或者,改变

char* str = func2();

char* str = showMsg();

hellofun.c 中。

关于c - 出现链接错误 : Some Makefile Issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18863050/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com