Helpful ReplyHot!Incompatible implicit declaration of built-in function 'snprintf' on XC161.15 Compiler

Author
cwanish
Starting Member
  • Total Posts : 36
  • Reward points : 0
  • Joined: 2015/11/09 00:24:07
  • Location: Poland
  • Status: offline
2015/11/26 00:00:01 (permalink)
0

Incompatible implicit declaration of built-in function 'snprintf' on XC161.15 Compiler

Good morning,

I have to convert integer values to array. Previously I used to use itoa().
In xc16 1.24 itoa() was working, but in 1.25 itoa() is unavailiable. So I started using snprintf() instead.

In 1.24 it was ok. In 1.25 it also works, but I get warnings:


wyswietlacz.c:67:5: warning: implicit declaration of function 'snprintf'
wyswietlacz.c:67:5: warning: incompatible implicit declaration of built-in function 'snprintf'
wyswietlacz.c: In function 'displaySERVICE_MODBUS_SCREEN':
wyswietlacz.c:116:5: warning: incompatible implicit declaration of built-in function 'snprintf'


Does somebody know what is the reason? I am really worried about this warning. I have stdio.h included.
#1
Aussie Susan
Super Member
  • Total Posts : 3249
  • Reward points : 0
  • Joined: 2008/08/18 22:20:40
  • Location: Melbourne, Australia
  • Status: offline
Re: Incompatible implicit declaration of built-in function 'snprintf' on XC161.15 Compi 2015/11/26 18:27:15 (permalink) ☄ Helpfulby cwanish 2015/11/27 00:16:58
+3 (3)
Also be aware that using the printf family greatly increases the memory footprint and the runtime. Basically you need to have available ALL of the code to translate any of the possible format that can be interpreted by the printf format string (which generally means code taking up ROM that will never be used) as well as the run-time interpretation of the format string which is generally constant.
I would concentrate on getting the itoa function approach working.
You may need to download the library code separately as it is no longer bundled with the compiler.
Susan
#2
jtemples
Super Member
  • Total Posts : 10857
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: Incompatible implicit declaration of built-in function 'snprintf' on XC161.15 Compi 2015/11/26 19:13:25 (permalink)
+2 (2)
Did you include stdio.h?
#3
ric
Super Member
  • Total Posts : 22101
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: Incompatible implicit declaration of built-in function 'snprintf' on XC161.15 Compi 2015/11/26 19:26:29 (permalink)
+1 (1)
Bottom of post#1 says he did.

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#4
jtemples
Super Member
  • Total Posts : 10857
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: Incompatible implicit declaration of built-in function 'snprintf' on XC161.15 Compi 2015/11/26 21:13:46 (permalink)
+2 (2)
It works fine for me with 1.25.  I'm guessing you've enabled the legacy C library which might not have snprintf.  Note that snprintf is not in the libraries manual, so it's not especially reasonable to expect it to be available.
#5
cwanish
Starting Member
  • Total Posts : 36
  • Reward points : 0
  • Joined: 2015/11/09 00:24:07
  • Location: Poland
  • Status: offline
Re: Incompatible implicit declaration of built-in function 'snprintf' on XC161.15 Compi 2015/11/27 00:38:02 (permalink)
0
jtemples

It works fine for me with 1.25.  I'm guessing you've enabled the legacy C library which might not have snprintf.  Note that snprintf is not in the libraries manual, so it's not especially reasonable to expect it to be available.





I guess you mean this box in properties:
I have it unmarked, but it seems to have no influence on my warning. I get them even if i mark this box.


(I wanted to add here a screen of Properties window with a checkbox of "Use legacy libc" unchecked, but I dont have permission to post images in this forum yet...)



You are right Aussie Susan, it takes almost 4000kB to use snprintf.
Do you have itoa() implementation that works exacly like normal itoa()?
I dont know how to add the library with itoa(), if I would like to use itoa() from 1.24 in 1.25.
Could you help me please?
post edited by cwanish - 2015/11/27 01:16:55
#6
crosland
Super Member
  • Total Posts : 1211
  • Reward points : 0
  • Joined: 2005/05/10 10:55:05
  • Location: Bucks, UK
  • Status: offline
Re: Incompatible implicit declaration of built-in function 'snprintf' on XC161.15 Compi 2015/11/27 01:16:22 (permalink)
+2 (2)
cwanish
I have stdio.h included.

Where? Show the complete source code, or a cut-down version that exhibits the problem.
#7
cwanish
Starting Member
  • Total Posts : 36
  • Reward points : 0
  • Joined: 2015/11/09 00:24:07
  • Location: Poland
  • Status: offline
Re: Incompatible implicit declaration of built-in function 'snprintf' on XC161.15 Compi 2015/11/27 01:22:11 (permalink)
+1 (1)
I have many files in project. I use snprintf only in "wyswietlacz.c"


i have there:
#include <stdio.h>
and later i use snpfintf(). Only in "wyswietlacz.c"
 
I dont include stdio.h  in "wyswietlacz.h".
I dont get warnings using printf().
 
(wyswietlacz is polish word for LCD or display, sorry for this)
 
Now I need itoa implementation, due to big snprintf() resources usage.
 
 
post edited by cwanish - 2015/11/27 05:46:53
#8
NKurzman
A Guy on the Net
  • Total Posts : 16122
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: Incompatible implicit declaration of built-in function 'snprintf' on XC161.15 Compi 2015/11/27 09:43:58 (permalink)
+2 (2)
Google Itoa() code or source.
It is not a very big function.
#9
I1nk
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2016/01/28 07:47:30
  • Location: 0
  • Status: offline
Re: Incompatible implicit declaration of built-in function 'snprintf' on XC161.15 Compi 2016/01/28 16:19:20 (permalink)
+1 (1)
I was having the same issue as the author, but I found that adding this flag fixed the warning (-no-legacy-libc). I'm just posting this here to help someone else since I find this post quite easily when looking for an answer. 
 
#10
bokske
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2016/04/08 06:38:30
  • Location: 0
  • Status: offline
Re: Incompatible implicit declaration of built-in function 'snprintf' on XC161.15 Compi 2016/06/13 02:55:41 (permalink)
+1 (1)
Ticking off the checkbox "Use legacy lib" like cwanish tried, did work for me.Compiler warning about implicit function declaration snprintf() disappeared (tested in MPLab-X v3.26 and v3.30).
The effect is exactly what l1nk did by hand : it adds option -no-legacy-libc to every xc16 compile line.
#11
hasanyildiz
Starting Member
  • Total Posts : 46
  • Reward points : 0
  • Joined: 2015/09/04 03:33:31
  • Location: 0
  • Status: offline
Re: Incompatible implicit declaration of built-in function 'snprintf' on XC161.15 Compi 2016/06/13 07:25:11 (permalink)
0
you can use sprintf but i suggest write your own code for converting it will be simple and save program memory and also your application run faster....
 
#12
northernLad
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2018/07/17 01:43:27
  • Location: 0
  • Status: offline
Re: Incompatible implicit declaration of built-in function 'snprintf' on XC161.15 Compi 2018/08/10 03:16:58 (permalink)
0
Ok doesn't matter, I was using legacy libc
#13
Jump to:
© 2018 APG vNext Trial Version 4.5