I'm programming a queue of my own struct data type in Turbo C++ 3.0, I can't build my project because TC presents me an error message of Undefined symbol when it try to linked it.
I have the following queue.h file
#include <stdio.h>
struct pcb{
int *QueueBase;
char id;
int quantum;
};
typedef struct pcb far * ppcb;
typedef struct nodocola far * pnodocola;
struct nodocola{
ppcb a;
pnodocola ant;
};
void insertProcess(ppcb arg1);
ppcb getProcess();
And my file queue.cpp
#include<stdlib.h>
#include<stdio.h>
#include<cola.h>
struct pcb{
int *QueueBase;
char id;
int quantum;
};
typedef struct pcb far * ppcb;
typedef struct nodocola far * pnodocola;
struct nodocola{
ppcb a;
pnodocola ant;
};
pnodocola base = (pnodocola)malloc(sizeof(pnodocola*));
void insertProcess(ppcb arg1){
base->a = arg1;
pnodocola tmp = (pnodocola)malloc(sizeof(pnodocola*));
tmp = base;
base = (pnodocola)malloc(sizeof(pnodocola*));
base->ant = tmp;
}
ppcb getProcess(){
pnodocola tmp = (pnodocola)malloc(sizeof(pnodocola*));
tmp = base->ant;
base = tmp->ant;
return tmp->a;
}
And the file where I include my file queue.h:
#include<queue.h>
#include<dos.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
void interrupt myTimer(...);
void interrupt (*prev)(...);
ppcb actual = (ppcb)malloc(sizeof(ppcb*));
int ticks;
const quantum = 4;
void main()
{
clrscr();
prev=getvect(8);
setvect(8,myTimer);
getch();
disable();
setvect(8,prev);
enable();
}
void interrupt myTimer(...)
{
(*prev)();
}
void init(...)
{
actual->id='A';
actual->quantum = quantum;
insertProcess(actual);
}
Error: Undefined symbol insertProcess(ppcb far)*
I'm working in a virtual machine with Windows XP 32 bits.
Edit: Sorry I have a mistake, I rename my file from cola.h to queue.h when I write the question, but the #include is correctly and the error is present.
And are you actually linking with the object file produced by queue.cpp
? It's not enough to just include the header file in your main code, you have to link both the main code and the queue code when you create the executable.
And, as an aside, why are you using such an archaic C implementation when far better, far more modern and just-as-cheap options are available?
In order to make Turbo C compile multiple source files, I think you have to create a project and then add the C files to that project. It will then know it has to compile and link all those source files in the project.
If you just have a single source file (no project), it treats it as a project with just that file.