ATMEL studio 7 compile error,help me,thanks!

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  • OS : Microsoft Windows 10 Home,64bit
  • AS7 Version: 7.0.1931
  • When I compile the project with ATMEL studio 7, the following error message appears.
  • What is the reason for this error message?Thanks!
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The error means that the function was not found (during linking)
.
Best guess why would be that you have forgotten to add a2d.c to your project.

:: Morten

 

(yes, I work for Microchip, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

meolsen wrote:
Best guess why would be that you have forgotten to add a2d.c to your project

Indeed.

 

Probably, you have #included some header file - say, a2d.h - which declares the functions (ie, just provides prototypes), but have omitted to provide anything which actually defines them.

 

That is, you are missing the definitions - the "bodies" containing the executable code of the functions

 

Typically, definitions would be in a source file - say, a2d.c or a2d.S - or a pre-built binary library.

 

http://c-faq.com/decl/decldef.html 

 

 

EDIT

 

These are all just declarations; ie, function prototypes:

 

 

A definition would look like:

void a2dInit( void )
{
    // Some
    // code
    // here ...
}

and

u16 do_a2d( void )
{
    // Some
    // more
    // code
    // here ...

    return some_result;
}

 

#DeclarationDefinition #UndefinedReference

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Sep 6, 2018 - 08:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The tab bar in the picture suggest that the file with the a2d functions is probably AToD.c - the point the others are making here is that while you may have it in your editor, it is not listed as one of the compile targets in the project/solution. You need to add that file (use "add existing item") to the list of sources so it is compiled along with main.c. Clearly main.c is making calls to those functions but, because the file was not compiled there is no code for the functions. When the linker comes to try to link the main.c calls to some target code it cannot find the functions so outputs "undefined reference"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
The tab bar in the picture suggest that the file with the a2d functions is probably AToD.c 

Ah - I had missed that:

 

 

while you may have it in your editor

Which is what your screenshot extract shows

 

 it is not listed as one of the compile targets in the project/solution

which is shown in the 'Solution Explorer' window - usually to the right of the code editor; eg,

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
the 'Solution Explorer' window - usually to the right of the code editor

But it can be moved; in this example, it's to the left!

 

 

This video - from 0:52 to 2:30 - shows the process of adding existing files to a project:

 

https://youtu.be/MzPGygZ13Sw?t=5... (it's actually a SAM project, but that makes no difference here).

 

He adds both the .c and the .h - it it not necessary to add the .h, but it does no harm.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

awneil wrote:
it it not necessary to add the .h, but it does no harm.
For simple projects there's little point - after the first (successful) build it will be listed under "Dependencies" anyway. The only reason not to use dependencies is when the code tree gets huge and that starts to list literally hundreds of .h files - then navigating to the one you want becomes a pain so it makes sense to list it under the project. When I do that I apply filters so have "Source files" and "Header files" separate.

 

Of course the other way to get easy access to a particular .h is simply to find the line where it is #include'd, right click and "open file".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

An important thing for readers to note, though, is that adding a .h file to the project does not help the compiler to find it - that has to be done via the Include Paths setting:

 

Image result for atmel studio include path

 

Picture from https://www.avrfreaks.net/forum/how-specify-compiler-search-h-and-cpp-files-project-folder - which covers pretty much the same stuff!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I follow your advice and try and succeed.Thank you!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Excellent!

 

Now please mark the solution - see Tip #5.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...