Makefiles让我困惑。我所要做的就是将一些函数分离到一个单独的文件中,但是我无法让它编译。我遗漏了什么?谢谢!
Makefile:
all: clientfunctions client
clientfunctions.o: clientfunctions.c
gcc -c clientfunctions.c -o clientfunctions.o
client.o: client.c clientfunctions.o
gcc -c client.c -o client.o
client: client.o
gcc client.o -o client.c和.h文件也非常简单:
clientfunctions.h
#ifndef _clientfunctions_h
#define _clientfunctions_h
#endif
void printmenu();clientfunctions.c
#include <stdio.h>
#include "clientfunctions.h"
void printmenu() {
fprintf(stdout, "Please select one of the following options\n");
}client.c
#include "clientfunctions.h"
int main (int argc, char * argv[])
{
printmenu();
return 0;
}这是我正在犯的错误:
Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [clientfunctions] Error 1
发布于 2013-09-03 18:19:57
试试看以下几点。
all: client
clientfunctions.o: clientfunctions.c
gcc -c clientfunctions.c -o clientfunctions.o
client.o: client.c
gcc -c client.c -o client.o
client: client.o clientfunctions.o
gcc client.o clientfunctions.o -o client下面是编写这个Makefile的更惯用的方法。
all: client
client: client.o clientfunctions.o
$(CC) -o $@ $^发布于 2013-09-03 18:17:29
您需要编译两个.c文件并将它们链接到您的可执行文件中。您需要在您的clientfunctions.o目标中依赖于client,并在链接中包含此对象以完成此操作。
client: client.o clientfunctions.o
gcc client.o clientfunctions.o -o client发布于 2013-09-03 18:25:54
你工作太辛苦了。您可以依赖于隐式规则,并极大地简化makefile,其整个内容(可能,取决于您正在使用的是什么)非常简单,如:
client: client.o clientfunctions.ohttps://stackoverflow.com/questions/18598903
复制相似问题