所以我知道 .h 和 .c 文件,但我在编译代码时遇到问题。我缺少一些东西! Main.c 包含“Converter.h”,其中包含
#ifndef CONVERTER_H
#define CONVERTER_H
void runConverter(char *);
#endif
我的转换器.c 文件已实现..
#include "Converter.h"
#include "Stack.h"
#include "Queue.h"
#include <stdio.h>
#include <stdlib.h>
int checkChar(char input);
void printQueue(QueueP que);
void runConverter(char *input){ .... code etc (calls a stack and a queue
and does stuff)}
问题是,我在每个文件中都收到 undefined reference 。 .c 未在 Stack.h 或 Queue.h 中找到信息,并且 converterTester 未找到我的主 runConverter 函数。有点困惑,但我认为这是一件小事。有什么帮助吗?
最佳答案
没有看到其他文件,也不知道如何构建可执行文件,纯粹是猜测......
您需要编译每个源,并将所有对象链接在一起:
gcc -g -O2 -Wall -c Converter.c
gcc -g -O2 -Wall -c Stack.c
gcc -g -O2 -Wall -c Queue.c
gcc -g -o pgm Converter.o Stack.o Queue.o
前三行中的 -c
(仅编译)标志至关重要,您不希望编译器尝试一次性创建可执行文件。不,编译器不知道您想要在从 Converter.c
获取的可执行文件中包含哪些其他部分。在[SO]上,我们非常擅长猜测,但猜测是人类的事情,而不是编译器的事情。
关于c - 对 'specificFunction' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22259856/