我有一个需要编译的小项目。我有一个头文件和一个我创建的源代码,以及一个几乎为空的包含我的头文件的 driver.c。
观察:
// iol.h
#ifndef __IOL_HEADER
#define __IOL_HEADER
/* program: iol.h
date: 5 October 2010
*/
#define UNIX 1
#define WINDOWS 2
#define OS UNIX
#if OS == UNIX
#include <ncurses.h>
#elif OS == WINDOWS
#include <conio.h>
#include <windows.h>
// Function declarations!
#endif
void iol_init(void);
#endif
现在我的实现文件:
// iol.c
#include <string.h>
#include <stdlib.h>
#include "iol.h"
void iol_init(void) {
#if OS == WINDOWS
/* no startup required for windows */
#elif OS == UNIX
initscr();
noecho();
cbreak();
keypad(stdscr, 1);
// Implmntn continues....
现在包含我的标头并提供 main() 的驱动程序:
//main.c
#include "iol.h"
我的 bash 命令:
gcc iol.c driver.c -l"ncurses"
我回来了:
/tmp/ccmmW6hQ.o:iol.c:(.text+0x83f): first defined here
/tmp/ccwIKUaT.o: In function 'isEscaping':
driver.c:(.text+0xbab): multiple definition of 'isEscaping'
/tmp/ccmmW6hQ.o:iol.c:(.text+0xbab): first defined here
/tmp/ccwIKUaT.o: In function 'initSeq':
..
driver.c:(.text+0x149): undefined reference to 'iol_prnstr'
driver.c:(.text+0x178): undefined reference to 'iol_putch'
..
driver.c:(.text+0x726): undefined reference to 'iol_display'
collect2: ld returned 1 exit status
我只是想指出我可以在哪里编译它,然后开始把我的头发扯掉,因为我所有的段错误。我的设置有什么问题?我在 Gnu C 编译器上进行 RTFM 显然我正在做我应该做的事情,即在 iol.h 中声明东西,在iol.c中定义,然后在driver.c中使用它,这可能是非常微不足道的东西,也许我只需要第二眼:
我实际上得到了一长串错误,如果有人认为这是相关的,我很乐意发布整个源。