문제

So I know about .h and .c files, but I'm having a problem getting my code to compile. I'm missing something! The Main.c includes "Converter.h", which has

  #ifndef CONVERTER_H
  #define   CONVERTER_H

  void runConverter(char *);

  #endif 

and my converter.c file has the implementation..

#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)}

The problem is, I'm getting undefined reference in each of my files. The .c isn't finding the info in Stack.h or Queue.h and the converterTester isn't finding my main runConverter function. Kind of confused, but I think its something small. Any help?

도움이 되었습니까?

해결책

Without seeing the other files, and with no idea how you build the executable, pure guesswork...

You need to compile each of the sources, and link all the objects together:

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

The -c (compile only) flags in the first three lines are crucial, you don't want the compiler to try to create an executable in one go. And no, the compiler has no idea what other pieces you want to include in the executable gotten from Converter.c. Here on [SO] we are pretty good at guessing, but guessing is for humans, not compilers.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top