gpt4 book ai didi

c - Linux 中的 Makefile C

转载 作者:太空宇宙 更新时间:2023-11-03 23:53:39 25 4
gpt4 key购买 nike

我在 .c 文件和 main.c 中有 3 个函数,我想制作 make 文件,我在文件中写道:

# Indicate that the compiler is the gcc compiler

CC=gc

# Indicate to the compiler to include header files in the local folder
CPPFLAGS = -I

main: method1.o
main: method2.o
main: method3.o
main: method4.o
main.o: main.h

而方法 1、2、3、4 是 main .c 的函数,当我在 shell 中键入 make 时遇到以下问题:

make
gcc -I -c -o method1.o method1.c
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [method1.o] Error 1

最佳答案

如果您的项目包含以下文件:method1.c method2.c method3.c method4.cmain.c

你可以使用下面的make文件

CPPFLAGS=-I/path/to/header/files
CC=gcc
all: main

%.o: %.c
$(CC) $(CPPFLAGS) -c -o $@ $^

main: method1.o method2.o method3.o method4.o main.o
$(CC) -o $@ $^

关于c - Linux 中的 Makefile C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13641970/

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