我想编写一个Makefile来编译一个目录中的多个文件。在文件夹中,我有5-1.c5-2.c5-3.c,它们是主要程序。我还拥有字符串.c字符串.h和the es.h文件。我的制作文件
all: 5-1 5-2 5-3
5-1: 5-1.c getch.c
gcc -Wall -v -g -o 5-1 5-1.c getch.c
5-2: 5-2.c getch.c
gcc -Wall -g -o 5-2 5-2.c getch.c
// The issues happens here. I does not generate string.o
// Also, I feel the format of 5-3 does not looks correct.
// I do not know how to write it here.
5-3: 5-3.o string.o
gcc -Wall -g -o 5-3 5-3.o string.o
string.o: string.c string.h
gcc -Wall -g -o string.c string.h types.h
clean:
rm -f 5-1 5-2 5-3
rm -rf *.dSYM
当我从终端运行make时,它将创建5-1、5-2和5-3作为执行的程序。问题发生在5-3.主程序为5-3.c,它包含字符串.c。
头文件string.h .h包含The es.h。如何修改gcc的5-3来编译这个程序.
我的系统是Mac。$ gcc -配置有:--prefix=/Applications/Xcode.app/Contents/Developer/usr -with-gxx-include-dir=/usr/include/c++/4.2.1 Apple版本6.0 (clang-600.0.57) (基于LLVM 3.5svn) Target: x86_64 apple-darwin13.4.0线程模型: posix
我的string.c .c文件
#include "string.h"
char *strcat(char *dst, const char *src)
{
char* cp = dst;
while(*cp) {
cp++;
}
while(*src)
{
*cp++ = *src++;
}
return dst;
}
我的字符串文件:
#ifndef _STRING_H
#define _STRING_H
#include <stdio.h>
#include "types.h"
#ifndef NULL
#define NULL 0
#endif
char *strcat(char *, const char *);
#endif /* _STRING_H */
我的类型。h文件:
#ifndef _SIZE_T_DEFINED
#define _SIZE_T_DEFINED
typedef unsigned int uint32_t;
#endif
我觉得Mac和其他linux系统有很大的不同。请告知是否有人可以在此基础上编写正确的Makefile。谢谢。
发布于 2015-07-18 20:27:26
问题在于您制定string.o
的规则
string.o: string.c string.h
gcc -Wall -g -o string.c string.h types.h
实际上,菜谱并不创建目标文件。我怀疑您希望使用-c
而不是-o
,或者可能使用-c -o string.o
。
此外,尽管将头作为先决条件列出是完全合理的,但是在编译命令中列出它们是不正常的。
https://stackoverflow.com/questions/31494877
复制相似问题