identifier "snprintf" is undefined

14.3k Views Asked by At

I am trying to compile a console C application on HP-UX machine using the aCC compiler [HP C/aC++ B3910B A.06.26].The compilation always failing with the below error :

******"Common/Common.c", line 153: error #2020: identifier "snprintf" is undefined
          snprintf( BufferMessage, MSG_SIZE,
          ^
1 error detected in the compilation of "Common/Common.c".
gmake: *****[Common/Common.o] Error 2********

However the Common.C file include already the library which contain normally the method snprintf. any idea to solve this isse plz? Thanks in advance for all

2

There are 2 best solutions below

8
On

snprintf() was introduced in C99, and is defined in <stdio.h>, so your compiler must support that version of the C standard. If it does not support C99 then use sprintf() instead.

2
On

Version 6 of the HPUX C compiler is C99-compliant but you may need switches to enable it.

The 6.20 release notes stated that the next release should switch the default mode from C89 to C90, and you're running 6.26. It appears that it did happen in 6.25, which was the release following 6.20.

You could force C99 mode by using cc -AC99 (or cc -Ae now that C99 is the default) to see if that helps. It may be that, even though the default C compilation mode is C99, you still have to specify it's C rather than C++.

Some other things to check:

  • See if you've included the stdio.h header.
  • See if you get a similar problem with just printf, which is also in that header.
  • Run the compiler generating pre-processor output (cc -E) and check that it's defined somewhere.