assert() gives me "incompatible implicit declaration of built-in function 'abort'"

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am trying to use the assert() function from assert.h in my code:

 


#include <assert.h>
// ...
char txok;
// ...
assert(txok);

When I compile, I get this error: incompatible implicit declaration of built-in function 'abort' [enabled by default]

 

I then searched and found abort() in stdlib.h. If I include that file as well, everything seems hunky dory. Does assert.h really require that you include stdlib.h as well, or is there something else wrong?

 

Atmel Studio 6.0

AVR GCC 3.4.0.65

 

 

/Jakob Selbing

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

Just tried this:

C:\SysGCC\avr\bin>type test.c
#include <assert.h>

char foo;

int main(void) {
        assert(foo);
}

C:\SysGCC\avr\bin>avr-gcc -mmcu=atmega16 test.c -o test.elf

C:\SysGCC\avr\bin>

No error using avr-gcc 5.3.0.

 

EDIT: I just tried a couple more versions. 4.5.3 (the one in Ubuntu 12.04) does give the warning. 4.9.2 (the latest toolchain from Atmel - the one in Studio 7) does not give the warning.

 

I believe you Studio 6 probably has avr-gcc version 4.8.2 so it looks like this has been fixed between 4.8.2 and 4.9.2

 

Of course the error probably isn't the compiler itself but a change in the assert.h file in AVR-LibC - so that's what you probably have that is out of date.

Last Edited: Fri. Aug 19, 2016 - 10:47 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, so now I'm really confused! When I look at the revision tracker for AVR-LibC I find:

 

http://svn.savannah.nongnu.org/v...

 

A file that has not changed in 4 years and 6 months. And yet virtually the first thing that does is:


#undef assert

#include <stdlib.h>

Oh, wait a monent. The change that was made 4.5 years ago was:

 

http://svn.savannah.nongnu.org/v...

 

See revision 2290:

Fix for bug #35398: assert doesn't work unless stdlib.h is also	included

* include/assert.h: Include <stdlib.h>.
* NEWS: Add to fixed bug list.

so it does seem a bit of a shame that it's taken 4.5 years for this fix to make it through to currently issued compiler distributions! (you must have the 2007 version).

Last Edited: Fri. Aug 19, 2016 - 10:52 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I am using quite an old version (specified in my OP). Maybe it's time to upgrade soon...

/Jakob Selbing