Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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

Status
Not open for further replies.

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
    1.jpg
    143.5 KB · Views: 393
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

  • htest.zip
    11.7 KB · Views: 268
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top