Ask a Question related to UNIX Programming, Design and Development.
-
Daihard #1
swprintf and GCC 2.96
Hi.
I need to compile a C++ application that utilizes various Unicode functions,
such as swprintf and vswprintf, with GCC 2.96 (for Red Hat 7.3). I had no
trouble compiling the code on GCC 3.2 (Red Hat 8.0) without any "special"
compiler or linker flags. However, the same process results in a compile
error with GCC 2.96, saying `swprintf' undeclared (first use this
function). Here is the test code:
/* ===== code begins ====== */
#include <stdio.h>
#include <wchar.h>
int main(int argc, char *argv[])
{
wchar_t wcTest[21];
swprintf(wcTest, 21, L"This is a test\n");
return 0;
}
/* ===== code ends ====== */
Here is the actual compile command. Nothing fancy.
[dtoyama@daihard-lnx test] g++ -c test.cpp -o test.o
Could anyone shed some light on this?
Thanks in advance,
Dai
--
Daigoro F. Toyama
RLU #281828
KDE 3.0.5 / RedHat 7.3 (kernel 2.4.20-13)
Mozilla Firebird 0.6 (2003-07-21)
Daihard Guest
-
James Antill #2
Re: swprintf and GCC 2.96
On Wed, 23 Jul 2003 00:55:36 +0000, Daihard wrote:
[snip ... ]> Hi.
>
> I need to compile a C++ application that utilizes various Unicode functions,
> such as swprintf and vswprintf, with GCC 2.96 (for Red Hat 7.3). I had no
> trouble compiling the code on GCC 3.2 (Red Hat 8.0) without any "special"
Here add...> /* ===== code begins ====== */
#define _GNU_SOURCE 1
You should alwyas add -W -Wall IMO, although that doesn't do much here.> #include <stdio.h>
> #include <wchar.h>
>
> int main(int argc, char *argv[])
> {
> wchar_t wcTest[21];
>
> swprintf(wcTest, 21, L"This is a test\n");
>
> return 0;
> }
>
> /* ===== code ends ====== */
>
> Here is the actual compile command. Nothing fancy.
>
> [dtoyama@daihard-lnx test] g++ -c test.cpp -o test.o
--
James Antill -- [email]james@and.org[/email]
Need an efficent and powerful string library for C?
[url]http://www.and.org/vstr/[/url]
James Antill Guest
-
stephan beal #3
Re: swprintf and GCC 2.96
Daihard wrote:
Be aware that RedHat was the only vendor, as far as i am aware, to ship gcc> I need to compile a C++ application that utilizes various Unicode
> functions,
> such as swprintf and vswprintf, with GCC 2.96 (for Red Hat 7.3). I had no
> trouble compiling the code on GCC 3.2 (Red Hat 8.0) without any "special"
> compiler or linker flags. However, the same process results in a compile
> error with GCC 2.96, saying `swprintf' undeclared (first use this
> function). Here is the test code:
2.96, and their doing so caused a big ruckuss in the Open Source world. The
GNU team never released 2.96 and does not even host it on their server,
which implies that they do not consider it to be worth releasing:
[url]ftp://ftp.gnu.org/pub/gnu/gcc[/url]
--
----- stephan beal
Registered Linux User #71917 [url]http://counter.li.org[/url]
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.
stephan beal Guest
-
Daihard #4
Re: swprintf and GCC 2.96
"James Antill" <james-netnews@and.org> wrote...
functions,> On Wed, 23 Jul 2003 00:55:36 +0000, Daihard wrote:
>> > I need to compile a C++ application that utilizes various Unicodeno> > such as swprintf and vswprintf, with GCC 2.96 (for Red Hat 7.3). I had"special"> > trouble compiling the code on GCC 3.2 (Red Hat 8.0) without anyThanks! Worked like a charm! Just for my future reference, what does this>
> Here add...
>
> #define _GNU_SOURCE 1
macro definition do? Is this a special setting for GCC 2.96?
I will look into those two flags. Again, thanks much for your help.> You should alwyas add -W -Wall IMO, although that doesn't do much here.
Dai
Daihard Guest
-
Sven Gohlke #5
Re: swprintf and GCC 2.96
Michael B Allen wrote:
In <features.h>, where else?>>>>>>> Here add...
>>>>
>>>> #define _GNU_SOURCE 1
>>>
>>> Thanks! Worked like a charm! Just for my future reference, what does
>>> this macro definition do? Is this a special setting for GCC 2.96?
>> Peruse /usr/include/features.h
>>
>> As for why 2.96 needs _GNU_SOURCE, I don't know. It could be quirk, or
>> the state of the function in various standards at the time.
>>
>> _GNU_SOURCE is a catchall. It seems to turn _everything_ on, but be
>> careful, because some semantics differ between BSD, SYSV, POSIX, etc,
>> such as w/ signal(2). Blindly defining _GNU_SOURCE may change the
>> behavior of some things.
> I believe the preferred technique is to code to a standard. I don't
> recall in which standard swprintf and vswprintf first appeared but they
> are in C99 so with GCC you would might use:
>
> $ gcc -Wall -W -std=c99 ...
>
> But I have a helluva time working like that. Usually I just add prototypes
> manually and try not to do anything obviously non-portable. These
> functions also appear in POSIX which is easier to code to. What's the
> GCC flag for the POSIX stadards? Anyone know where the list is? I've
> seen it. Really.
--
Best Regards
Sven
Sven Gohlke Guest
-
William Ahern #6
Re: swprintf and GCC 2.96
Michael B Allen <mba2000@ioplex.com> wrote:
<snip>> I believe the preferred technique is to code to a standard. I don't
> recall in which standard swprintf and vswprintf first appeared but they
> are in C99 so with GCC you would might use:> $ gcc -Wall -W -std=c99 ...c/o /usr/include/features.h, in Linux at least. It's not possible to have a> But I have a helluva time working like that. Usually I just add prototypes
> manually and try not to do anything obviously non-portable. These
> functions also appear in POSIX which is easier to code to. What's the
> GCC flag for the POSIX stadards? Anyone know where the list is? I've
> seen it. Really.
POSIX command-line compiler flag, because POSIX is purely an interface.
-std=c99 gives you variable argument macros, etc; language level stuff. I'd
be surprised if -std=c99 _gave_ you swprintf(), as opposed to defining
_POSIX_SOURCE or _ISOC99_SOURCE (unless swprintf() is a built-in).
-std=c99 is similar to the -ansi flag (i.e. -std=c89 or something).
You could still do gcc -ansi -D_POSIX_SOURCE ... etc.
- Bill
William Ahern Guest
-
Daihard #7
Re: swprintf and GCC 2.96
Michael B Allen wrote:
I actually tried adding the prototype of vswprintf. That got me through the> $ gcc -Wall -W -std=c99 ...
>
> But I have a helluva time working like that. Usually I just add prototypes
> manually and try not to do anything obviously non-portable. These
> functions also appear in POSIX which is easier to code to. What's the
> GCC flag for the POSIX stadards? Anyone know where the list is? I've
> seen it. Really.
compilation, but the linking failed. I tried adding "-lw" assuming all the
Unicode functions were defined there, but it did not work.
Dai
--
Daigoro F. Toyama
RLU #281828
KDE 3.0.5 / RedHat 7.3 (kernel 2.4.20-13)
Mozilla Firebird 0.6.1 (2003-07-26)
Daihard Guest
-
Michael B Allen #8
Re: swprintf and GCC 2.96
On Mon, 28 Jul 2003 00:30:28 -0400, Daihard wrote:
Sounds like your libc doesn't have it. I'm using glibc-2.2.5. I> Michael B Allen wrote:
>>>> $ gcc -Wall -W -std=c99 ...
>>
>> But I have a helluva time working like that. Usually I just add
>> prototypes manually and try not to do anything obviously non-portable.
>> These functions also appear in POSIX which is easier to code to. What's
>> the GCC flag for the POSIX stadards? Anyone know where the list is?
>> I've seen it. Really.
> I actually tried adding the prototype of vswprintf. That got me through
> the compilation, but the linking failed. I tried adding "-lw" assuming
> all the Unicode functions were defined there, but it did not work.
don't know when those functions were added. Look for the prototype in
/usr/include/wchar.h. You definately do not need to link with any lib
for the wide character functions.
Mike
Michael B Allen Guest



Reply With Quote

