问题
My main.c is as below
#include <avr/io.h>
#include<avr/interrupt.h>
#include<util/delay.h>
#include <string.h>
#include "main.h"
#include "globle.h"
#include "LCD.h"
int main()
{
...
...
...
lcdInit(0xc0);
lcdScreen(0);
.
.
.
return 0;
}
The definition of lcdInit(0xc0); and lcdScreen(0); is in my lcd.c file and I have a header file lcd.h having the following lines:
void lcdInit(char);
void lcdScreen(char);
But still I am getting:
C:\Documents and Settings\Tanv\My Documents\my_project5\default/../Main.c:95: >undefined >reference to `lcdInit'
and
C:\Documents and Settings\Tanvr\My Documents\my_project5\default/../Main.c:96: undefined reference to `lcdScreen'
What is wrong here?
回答1:
This is a linker error.
You are not building your program properly, you need to compile all C files together, like so:
$ gcc-avr -o program main.c lcd.c
or link them together from object files if you compile separately.
回答2:
Add source and header files to your project by 1. Right click "Source Files" then "Add Existing Source File(s)" 2. Right click "Header Files" then "Add Existing Header File(s)"
Refer to Add Source to Project Step 6.
来源:https://stackoverflow.com/questions/18533787/undefined-reference-to-in-avr-gcc