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?
 
Can you post all the output messages from the build (compile and link)

It will help us better answer your question.
 
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: 400
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: 275
Last edited:
You have file ledon.c in your project as a header file. It does not get compiled.

Try it as a source file.

I have a good deal of experience in C but do not use winAVR so I am not setup to run the project.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…