$project
|
+------------+----------------+----------------+
| | | |
gestore/ tipoA/ tipoB/ shared/
| | | |
+ + + +
| | | +--------|------------------+
gestore.c tipoA.c tipoB.c/ funzioni.c/.h sem.c/.h gF.c./
您好,我想为这个项目创建一个makefile,它执行以下命令:
共享文件夹中的第1步:
gcc -c -o gestioneFile gestioneFile.c
gcc -c -o sem sem.c
gcc -c -o funzioni funzioni.c
FOLDER类型中的第2步:
gcc -o tipoA tipoA.c ../shared/funzioni ../shared/sem ../shared/gestioneFile
tipoB文件夹中的第3步:
gcc -o tipoB tipoB.c ../shared/funzioni ../shared/sem ../shared/gestioneFile
第四步在gestore文件夹中:
gcc -o gestore gestore.c ../shared/funzioni ../shared/sem ../shared/gestioneFile
./gestore
这是我的makefile,但它不起作用:
#Makefile
cc=gcc
./gestore/gestore: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o ./tipoA/tipoA.o ./tipoB/tipoB.o ./gestore/gestore.o
./gestore/gestore
./shared/gestioneFile.o:
cc -c -o ./shared/gestioneFile ./shared/gestioneFile.c
./shared/sem.o:
cc -c -o ./shared/sem ./shared/sem.c
./shared/functions.o:
cc -c -o ./shared/funzioni ./shared/funzioni.c
./tipoA/tipoA.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
cc -o ./tipoA/tipoA ./tipoA/tipoA.c ./shared/funzioni ./shared/sem ./shared/gestioneFile
./tipoB/tipoB.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
cc -o ./tipoB/tipoB ./tipoB/tipoB.c ../shared/funzioni ../shared/sem ../shared/gestioneFile
./gestore/gestore.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
cc -o ./gestore/gestore ./gestore/gestore.c ./shared/funzioni ./shared/sem ./shared/gestioneFile
编辑:@HardcoreHenry这是我的makefile,但它给出了错误:*****缺少分隔符。**
#Makefile
cc=gcc
./gestore/gestore: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o ./tipoA/tipoA.o ./tipoB/tipoB.o ./gestore/gestore.o
./gestore/gestore
./shared/gestioneFile.o:
cc -c -o ./shared/gestioneFile.o ./shared/gestioneFile.c
./shared/sem.o:
cc -c -o ./shared/sem.o ./shared/sem.c
./shared/funzioni.o:
cc -c -o ./shared/funzioni.o ./shared/funzioni.c
./tipoA/tipoA.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
cc -o ./tipoA/tipoA.o ./tipoA/tipoA.c ./shared/funzioni.o ./shared/sem.o ./shared/gestioneFile.o
./tipoB/tipoB.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
cc -o ./tipoB/tipoB.o ./tipoB/tipoB.c ../shared/funzioni.o ../shared/sem.o ../shared/gestioneFile.o
./gestore/gestore.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
cc -o ./gestore/gestore.o ./gestore/gestore.c ./shared/funzioni.o ./shared/sem.o ./shared/gestioneFile.o
求助(即使第一条规则不执行文件):
./gestore/gestore: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o ./tipoA/tipoA ./tipoB/tipoB ./gestore/gestore
./gestore/gestore
./shared/gestioneFile.o:
gcc -c -o ./shared/gestioneFile ./shared/gestioneFile.c
./shared/sem.o:
gcc -c -o ./shared/sem ./shared/sem.c
./shared/funzioni.o:
gcc -c -o ./shared/funzioni ./shared/funzioni.c
./tipoA/tipoA: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
gcc -o ./tipoA/tipoA ./tipoA/tipoA.c ./shared/gestioneFile ./shared/sem ./shared/funzioni
./tipoB/tipoB: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
gcc -o ./tipoB/tipoB ./tipoB/tipoB.c ./shared/gestioneFile ./shared/sem ./shared/funzioni
./gestore/gestore: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
gcc -o ./gestore/gestore ./gestore/gestore.c ./shared/gestioneFile ./shared/sem ./shared/funzioni
以下行将为您提供这些错误:
./tipoA/tipoA.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
cc -o ./tipoA/tipoA ./tipoA/tipoA.c ./shared/funzioni ./shared/sem ./shared/gestioneFile
首先,正如@Nonyme指出的那样,你输出的是./tipoA/tipoA
而不是./tipoA/tipoA.o
。但这不会导致编译失败。
导致失败的原因是它试图使用./shared/funzioni
作为输入 - 该文件不存在。 (注意makefile目标依赖于./shared/funzioni.o
,它必须在调用此配方之前构建,但它不会生成shared/funzioni
(没有.o
)
您需要将.o
添加到cc命令的目标和来源。
我还建议使用$(CC)
,并查找automatic variables - 特别是$@
和$^
为您的食谱。这种方式更整洁,更不容易出错。
./tipoA/tipoA.o: ./shared/gestioneFile.o ./shared/sem.o ./shared/funzioni.o
$(CC) -o $@ $^