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

标签 c makefile

我正在尝试将 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/

相关文章:

c - Linux 相当于 GetCommandLine 和 CommandLineToArgv?

java - 使文件丢失,Eclipse

c - 推测条件执行 C/C++

c - 这应该是 int,那我们为什么要使用 %s?

makefile - 将日期和时间附加到 Linux makefile 中的环境变量

Makefile 依赖项不适用于虚假目标

c++ - Makefile 有两次看不到 main.o

android - AOSP 构建错误 : No config file found for TARGET_DEVICE

c - 如何将一系列整数变量乘以系数的总和分解回变量?

c - 单链表 c - 可以在此函数中未初始化地使用 (-Wall -Werror)