-
multiple source files
I am trying to compile with 2 .c files and a .h file
I have something like this
recognizer.c
Code:
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "recheader.h"
#define ENDOFINPUT "ENDOFINPUT"
Lexeme* lex();
int main(int argc, char *argv[])
{
int recognizer(char*);
recognizer(argv[1]);
}
int recognizer(char* filename)
{
Lexeme* lexeme;
lexInit(filename);
lexeme = lex();
while(strcmp(lexeme->type, ENDOFINPUT) != 0)
{
lexemeDisplay(lexeme);
lexeme = lex();
}
return 0;
}
recheader.h
Code:
#ifndef RECHEADER_H
#define RECHEADER_H
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef struct lexword
{
char type[15];
char value[100];
int value_length;
struct lexword *next;
}Lexeme;
typedef struct
{
struct lexword *Head;
}Header;
void lexInit(char* filename);
int lexemeDisplay();
function.c
Code:
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "recheader.h"
int lexemeDisplay();
Lexeme* lex();
void lexInit(char* filename)
{
:
:
}
Lexeme* lex()
{
:
:
:
}
int lexemeDisplay()
{
:
}
The problem is when I compile, I get this message
[Linker error] undefined reference to `lexInit'
[Linker error] undefined reference to `lex'
[Linker error] undefined reference to `lexemeDisplay'
[Linker error] undefined reference to `lex'
I realize this is probably trivial to most, but I have read a few tutorials and am still confused.
Any help would be appreciated.
-
Just tell the compiler all the names of your .c files
gcc recognizer.c function.c
When you have say more than 4 or 5 files, you'll want to explore the delights of makefiles.
-
Thanks for your help
where would I add this line?
-
-
bloodshed dev-C++, for some reason my program runs fine on microsoft compilers but develops linker errors on dev-c++.
where do I put the gcc... line on bloodshed though?
-
-
Right-click on your project and "Add to project"
Choose all the source files you want added.