Undefined reference to in AVR-GCC

孤人 提交于 2019-12-11 02:13:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!