3

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

Koushik Shetty
  • 2,146
  • 4
  • 20
  • 31
jamel
  • 303
  • 2
  • 7
  • 16

2 Answers2

4

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.

hmjd
  • 120,187
  • 20
  • 207
  • 252
  • This is version 6 of the compiler which is documented to support C99. – paxdiablo Apr 24 '13 at 08:31
  • @paxdiablo, I am unfamiliar with that compiler, any required compiler switches like `gcc`? – hmjd Apr 24 '13 at 08:32
  • According to HP the compiler [HP C/aC++ B3910B A.06.26] support C99. I am not developping the app we are just trying to compile it, this is a bit strance because I succeded to compile the same code with an older version of the same HP compiler. Thanks – jamel Apr 24 '13 at 08:33
  • 1
    @jamel, are there any compiler switches to enable C99 support? For example `gcc -std=c99` is required for the GNU C compiler. – hmjd Apr 24 '13 at 08:33
  • Yes this version support C99 – jamel Apr 24 '13 at 08:34
  • I didn't find any flag to set to enable C99 support, seems it is supported by default :) – jamel Apr 24 '13 at 08:40
  • @jamel, and there is `#include ` in the source file? – hmjd Apr 24 '13 at 08:43
  • @hmjd: yeah there is include to stdio.h and string.h #include #include #include #include – jamel Apr 24 '13 at 08:49
2

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.
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • great Man I added the -AC99 and the "identifier “snprintf” is undefined" disappared. Many thanks man and Thanks for ALL! – jamel Apr 24 '13 at 08:51
  • 1
    @jamel, it may be that it was compiling in C++ mode. It would be interesting to see if `-Ae` fixes it as well, since that would indicate that was the case. As stated, default C compilation mode is C99 as at 6.25, but it may be that you still have to tell it it's C. And, if this indeed is the solution, you're supposed to upvote and/or accept so correct answers rise to the top - that's how SO works. – paxdiablo Apr 24 '13 at 08:56