Author Topic: about the sprintf(........)!I can't use !  (Read 15696 times)

Offline tr111

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
about the sprintf(........)!I can't use !
« on: September 06, 2007, 09:27:52 AM »
I do that:

1. Remove typedef unsigned int size_t; from types.h
2. Add #include <stdio.h> at the line after #include "types.h" in config.h
3.#included <stdio.h>
4.sprintf(buffer, "err=%d \n",err); infnADC;


but in the CodeWarrior IDE

Link Error   : Undefined : "sprintf"
Referenced from "fnADC" in Watchdog.c

Link failed.

/*stdio.h*/

/* MSL
 * Copyright ?1995-2006 Freescale Corporation.  All rights reserved.
 *
 * $Date: 2006/02/08 20:34:05 $
 * $Revision: 1.35.2.3 $
 */

#ifndef _MSL_STDIO_H
#define _MSL_STDIO_H

#include <ansi_parms.h>

#if !_MSL_USING_MW_C_HEADERS
   #error You must have the non-MSL C header file access path before the MSL access path
#else

#include <cstdio>

#if defined(__cplusplus) && defined(_MSL_USING_NAMESPACE)
   using std::FILE;
   using std::fpos_t;
   using std::size_t;
   using std::clearerr;
   using std::fclose;
   using std::feof;
   using std::ferror;
   using std::fflush;
   using std::fgetc;
   using std::fgetpos;
   using std::fgets;
#if _MSL_OS_DISK_FILE_SUPPORT
   using std::fopen;
   using std::fprintf;
#endif /* _MSL_OS_DISK_FILE_SUPPORT */   /*- mm 030319 -*/
   using std::fputc;
   using std::fputs;
   using std::fread;
#if _MSL_OS_DISK_FILE_SUPPORT
   using std::freopen;
#endif /* _MSL_OS_DISK_FILE_SUPPORT */
   using std::fscanf;
   using std::fseek;
   using std::fsetpos;
   using std::ftell;
   using std::fwrite;
   using std::getc;
   using std::getchar;
   using std::gets;
#if _MSL_OS_DISK_FILE_SUPPORT   
   using std::perror;
#endif /* _MSL_OS_DISK_FILE_SUPPORT */
   using std::printf;
   using std::putc;
   using std::putchar;
   using std::puts;
#if _MSL_OS_DISK_FILE_SUPPORT
   using std::remove;
   using std::rename;
#endif /* _MSL_OS_DISK_FILE_SUPPORT */
   using std::rewind;
   using std::scanf;
   using std::setbuf;
   using std::setvbuf;
   using std::sprintf;
   using std::snprintf;
   using std::sscanf;
#if _MSL_OS_DISK_FILE_SUPPORT
   using std::tmpfile;
   using std::tmpnam;
#endif /* _MSL_OS_DISK_FILE_SUPPORT */
   using std::ungetc;
   using std::vfprintf;
   using std::vprintf;
   using std::vsprintf;
   using std::vfscanf;
   using std::vscanf;                  /*- mm 020326 -*/
   using std::vsscanf;
   using std::vsnprintf;
#if defined(__STDC_WANT_SECURE_LIB__) && __STDC_WANT_SECURE_LIB__
   using std::errno_t;
   using std::rsize_t;
   using std::fscanf_s;
   using std::scanf_s;
   using std::sscanf_s;
   using std::vfscanf_s;
   using std::vsscanf_s;
   using std::gets_s;
#if _MSL_OS_DISK_FILE_SUPPORT
   using std::fopen_s;
   using std::freopen_s;
   using std::tmpfile_s;
   using std::tmpnam_s;
#endif /* _MSL_OS_DISK_FILE_SUPPORT */
#endif /* __STDC_WANT_SECURE_LIB__ */
#endif /* defined(__cplusplus) && defined(_MSL_USING_NAMESPACE) */

#endif /* _MSL_USING_MW_C_HEADERS */

#endif /* _MSL_STDIO_H */

/* Change record:
 * hh  971206 Created.
 * hh  991112 Fixed using bug.
 * JWW 001208 Added case for targeting Mach-O
 * JWW 011027 Use _MSL_USING_MW_C_HEADERS as generic header test instead of specific Mach-O test
 * mm  020126 Included using vscanf, __unoriented, __wide_oriented, and __char_oriented
 * JWW 030224 Changed __NO_WIDE_CHAR flag into the new more configurable _MSL_WIDE_CHAR
 * mm  030314 Added wrappers for fwide
 * mm  030319 Moved wrapper for _No_Disk_File_OS_Support
 * JWW 031030 Added the __STDC_WANT_SECURE_LIB__ secure library extensions
 * cc  040217 Changed _No_Disk_File_OS_Support to _MSL_OS_DISK_FILE_SUPPORT
 */

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3238
    • View Profile
    • uTasker
Re: about the sprintf(........)!I can't use !
« Reply #1 on: September 06, 2007, 12:34:29 PM »
Hi

This looks to be a CW project issue. If you add the correct library it should then find it.

Please see the M5223X section for details, including the libraray which should be added (I have just added a foot note so that the information there is complete).

http://www.utasker.com/forum/index.php?topic=30.0

Regards

Mark


Offline ewan

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: about the sprintf(........)!I can't use !
« Reply #2 on: December 17, 2009, 02:08:09 AM »
I went through the whole thing of pointing to the new library. (It took me half a day to discover that you add the library to a lib folder you create in the files window of CW.) I added "#include <stdio.h>" to "config.h" and removed the offending typdef of "size_t" from "types.h".

Now "sprintf" works fine but "sscanf" does not. It always returns 0x0 whenever it scans for a number. I am using "C_4i_CF_SZ_MSL.a". Should it be another library?

Thanks in advance,
Ewan.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3238
    • View Profile
    • uTasker
Re: about the sprintf(........)!I can't use !
« Reply #3 on: December 20, 2009, 11:00:56 PM »
Hi Ewan

I don't have any experience with this from the CW library but I believe that malloc() is often used by such routines. If malloc() fails due to having no heap (or due to other malloc() related errors which are a bit sensitive in the CW library - search also the Freescale CW forum for various discussions and tips).

Ensure that malloc() has heap space available - you should find all info here: http://www.utasker.com/forum/index.php?topic=616.0 (and in its links) [HEAP_SIZE    = X; in the linker script].

Regards

Mark


Offline ewan

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: about the sprintf(........)!I can't use !
« Reply #4 on: December 22, 2009, 07:39:36 PM »
Mark,

All is well. It turned out that I needed more libraries.

-       C_4i_CF_MSL.a
-       C_4i_CF_Runtime.a
-       Fp_coldfire.a

All three are required. Since your examples do not need any libraries I had no idea.

Many thanks and a Merry Christmas to all.

Ewan.