Help:I write a simple library for winavr but it doesn't work

mohseni

New Member
Dear Members,

I'am trying to define a function(a simple function which make a led on/off) and add it to main source code by including a header but the main source couldn't determine/define the function. I recieve below error:

********* main.c12: undefined reference to 'ledon' ********

Would you please tell me where is problem?

%%%%%%%%% here is the codes %%%%%%%%%
main:
------------------------
#include <avr/io.h>
#include <util/delay.h>
#include "ledon.h"

int main()
{
DDRA=0xff;
while(1)
{
ledon();
}
}

--------------------------- Function( it's a simple function which make a led on/off---------

void ledon()

{
PORTA |= 0x80;
_delay_ms(100);
PORTA &= ~0x80;
_delay_ms(100);
}

------------------------- header---------------------
#ifndef MYHEADER_H
#define MYHEADER_H
void ledon();
#endif
 
If it was a linker error.

You need to compile the source file containing the ledon() function. Then link it with the object containing the main() function.

Including the header file tells the compiler what the function looks like (signature) but does not provide the function to the program. By including the object file created from this function you provide the code.

HTH
 
Last edited:
Thank you for response

please tell me how should I compile the source code and the link them . I made a project file and add the source files and h file to project and then from tools menu I use "make all" tab to complie the project. Did I do wrong?
 
Daer Member ,
I submit a jpg file which is a screen picture of software and you can see complete message error.
 

Attachments

  • 1.jpg
    143.5 KB · Views: 549
Dear sir,

I also submit a zip file consist of the project's files. maybe you can test it by yourself.

Thank you for spending time on my program.
 

Attachments

Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…