From: Wolfgang Denk Date: Wed, 08 Jul 2009 17:55:16 +0200 Subject: [U-Boot] Can't get sprintf to work in standalone program In-Reply-To: <1247062359.4070.21.camel@hejnfelt-2> References: <1247062359.4070.21.camel@hejnfelt-2> Message-ID: <20090708155516.F2794832E416@gemini.denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Dear Martin Hejnfelt, In message <1247062359.4070.21.camel@hejnfelt-2> you wrote: > > I'm trying to use the sprintf function in a C program written for > U-boot. As far as I understand, to get the function I have to add it to > the exports.h, _exports.h and exports.c file as per the > README.Standalone file in /doc (the function is declared in common.h). > Now if I do this, the program compiles fine, and all is dandy, until I > actually start using the function. It generates garbage. printf and > alike works fine, and the program runs like it should, except the places > where sprintf is used, I get garbage (meaning some environment variables > are looking pretty nasty since the result of the sprintf functions are > used for these). > When compiling I link to the examples/libstubs.a file and > lib_generic/libgeneric.a where the code I'm using should be present. Note that 1) linking libgeneric.a should not be needed and 2) doing so makes your standalone application to be GPLed. > When I do this, the line that defines the a[6] thing generates a > compiler error stating an undefined reference to memcpy. Since this > error is present every time I try to initialize a string (char*) or char > array I'm guessing this might be the problem, but I'm not sure... You probably have to come up with a linker script and a concept of where your data segment is located... Best regards, Wolfgang Denk -- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de The price of curiosity is a terminal experience. - Terry Pratchett, _The Dark Side of the Sun_