简体   繁体   中英

Undefined reference to in AVR-GCC

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?

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.

在此处输入图片说明

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.

I had the same problem and I added the files to the project from the beginning and they were compiled together. But this did not solve the problem and I accidentally noticed that I made a mistake, namely the file of the implementation of the functions of the library had the extension .c , and the main extension .cpp . To solve the problem, I simply reassembled the project in c format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM