【发布时间】:2015-11-28 00:56:24
【问题描述】:
我有以下 C 文件,我正在使用 Mac OS X GCC 编译器。 您会发现以下错误。
#include "support.h"
#ifdef _WIN32
#include <conio.h>
void support_init() {
// not needed
}
void support_clear() {
system("CLS");
}
int support_readkey(int timeout_ms) {
Sleep(timeout_ms);
if (!kbhit()) return 0;
return getch();
}
#else
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <sys/select.h>
void support_init() {
struct termios tio;
tcgetattr(STDIN_FILENO, &tio);
tio.c_lflag &= (~ICANON & ~ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &tio);
}
void support_clear() {
printf("\x1B[2J\x1B[0;0f");
}
int support_readkey(int timeout_ms) {
struct timeval tv = { 0L, timeout_ms * 1000L };
fd_set fds;
FD_ZERO(&fds);
FD_SET(0, &fds);
int r = select(1, &fds, NULL, NULL, &tv);
if (!r) return 0;
return getchar();
}
#endif
这是我的 Makefile:
CFLAGS=-std=c11 -Wall -g
CC=clang
all: snake
.PHONY: all clean
snake: snake.o support.o
snake.o: snake.c support.h
clean:
rm -f snake
rm -f snake.o support.o
当我尝试使用命令“make all”进行编译时,出现以下错误:
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
请帮忙。我是 C 新手 :-)
【问题讨论】:
-
您使用的是
clang,而不是gcc。 Makefile 明确指定它,并且错误消息清楚地表明它。如果您需要好的帮助,请直接说明您的故事(和标签)。 -
虽然错误信息有点不清楚,但很可能是由于
snake.c中缺少main()函数造成的。main()函数是程序的入口点;每个程序都必须有一个,在其源文件中的某个地方定义。 -
嗨,约翰,感谢您的帮助
-
snake.c 文件有一个空的主函数我必须在 Makefile 中输入“gcc”而不是“clang”吗?
标签: c gcc linker-errors