gpt4 book ai didi

c - GCC: undefined reference (Makefile 问题)

转载 作者:太空宇宙 更新时间:2023-11-04 07:12:43 24 4
gpt4 key购买 nike

尝试在 Makefile 规则下使用 gcc 编译这些文件。在 cygwin 上运行 gcc/make。

这是生成文件:

CC = gcc
CFLAGS = -g -O2 -Wall -std=c99
OBJECTS = simulation.o element.o

simulation.exe : $(OBJECTS)
$(CC) $(CFLAGS) -o simulation.exe $(OBJECTS)

simulation.o : file_priorite.o element.o
$(CC) $(CFLAGS) -c simulation.c

file_priorite.o: file_priorite.h element.o
$(CC) $(CFLAGS) -c file_priorite.c

element.o : element.h
$(CC) $(CFLAGS) -c element.c

clean:
rm -f *.o simulation.exe

并得到这些错误:

CLEAN SUCCESSFUL (total time: 52ms)
gcc -g -O2 -Wall -std=c99 -c element.c
gcc -g -O2 -Wall -std=c99 -c simulation.c
gcc -g -O2 -Wall -std=c99 -o simulation.exe simulation.o element.o
simulation.o: In function `main':
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:11: undefined reference to `construire'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:11:(.text.startup+0x17): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `construire'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:20: undefined reference to `ajouter_element'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:20:(.text.startup+0x69): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `ajouter_element'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:23: undefined reference to `consommer_element'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:23:(.text.startup+0x76): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `consommer_element'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:23: undefined reference to `consommer_element'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:23:(.text.startup+0x86): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `consommer_element'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:25: undefined reference to `obtenir_taille'
/cygdrive/d/Dropbox/UQAM AUTOMNE 2014/INF7330/lab10/lab10/simulation.c:25:(.text.startup+0x96): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `obtenir_taille'
collect2: error: ld returned 1 exit status
Makefile:6: recipe for target 'simulation.exe' failed
make: *** [simulation.exe] Error 1

有问题的功能都在file_priorite.c中实现。

有什么想法吗?

最佳答案

你需要有

OBJECTS = simulation.o element.o file_priorite.o

关于c - GCC: undefined reference (Makefile 问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27110745/

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