bug-ocrad
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-ocrad] Win32 configure Cygwin32 g++ 3.3.3 compile `snprintf' undecl


From: Chris K. Skinner
Subject: [Bug-ocrad] Win32 configure Cygwin32 g++ 3.3.3 compile `snprintf' undeclared
Date: Thu, 23 Feb 2006 11:39:55 -0500

The directory in which I have un-packed the archive has a space character in its name/path. Probably because of this, the configure command issued an error. Often a space or dollar sign or ampersand or other special shell character must be escaped via '\' character so that a generated / echoed path names are still usable in subsequent scripts or environment variable expansions. Sometimes using quotation marks around the offending path variable can fix things, but not always.

Then the make failed (during compile of a file using snprintf()).

I am an old C programmer from DEC VAX-11/780 days (circa 1985). I had not encountered
a function with this name before.

When I checked if snprintf() existed, I found it to be a circa 1999 vintage function (C99) whose prototype is only defined when a couple of pre-processor constants are defined or
undefined, as the case may be.

If possible, an older, more portable version function might be used in its place that would certainly help in portability issues for both compiling and linking in older c++ systems.

{
// If you don't care about link errors or portability, then you could insure that snprintf() is declared // properly by just putting in its usual prototype definition just after the function's opening brace. extern int std::snprintf(char *buf, const char *format, ...); // or whatever it really is...
 // use the function here...
} // end function or local block.

Presumably the n in the snprintf() function's name permits a limit be
placed on the resulting string's length. The same result can be accomplished by insuring that the passed parameters are of sane values, and then using something like the following
example...

#ifndef _MAXPATH
#define _MAXPATH _PATHMAX
#endif
{
 #define SIZELIMIT (_MAXPATH - 40)
  char * buf = new [_MAXPATH];
  if (number > (1 << 15)) {
    error(); // or some automatic limitation be imposed
  }
  if (strlen(fname) > _MAXPATH - 65) {
     error(); // or some automatic limitation be imposed
  }
  int icount = sprintf(buf, "format string %s-%03d", fname, number);
  if (count > SIZELIMIT) {
    error(); // or some automatic limitation be imposed
 }
 // Use buf here...
 deelete [] buf; // now we're done with buf
}

Here are the cut/paste messages of my installation session...

$ pwd
/cygdrive/c/My Download Files/ocrad-0.14

$ ./configure
[: Download: unknown operand
VPATH = .
prefix = /usr/local
datadir = $(prefix)/share
infodir = $(datadir)/info
mandir = $(datadir)/man
OK. Now you can run make.

$ make
g++  -Wall -W -O2 -c -o rational.o rational.cc
rational.cc: In member function `const char* Rational::to_decimal(int, int)
  const':
rational.cc:212: error: `snprintf' undeclared in namespace `std'
make: *** [rational.o] Error 1

$ g++ -v
Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/specs
Configured with: /gcc/gcc-3.3.3-3/configure --verbose --prefix=/usr --exec-prefi x=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/s hare/man --infodir=/usr/share/info --enable-languages=c,ada,c++,d,f77,java,objc, pascal --enable-nls --without-included-gettext --enable-libgcj --with-system-zli b --enable-interpreter --enable-threads=posix --enable-java-gc=boehm --enable-sj lj-exceptions --disable-version-specific-runtime-libs --disable-win32-registry
Thread model: posix
gcc version 3.3.3 (cygwin special)

TIA.  Kindest regards, C.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]