Hello, I have a problem with compiling my code...

Platform: Ubuntu Linux 10.04
Compiler: gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
IDE: Netbeans 6.9.1

My C program is required to exclusively deal with Unicode. I can use these functions just fine: wcscpy(), wcslen(), mbstowcs(), wcstombs(), snprintf()

The problem seems to only be when I use this function: swprintf()

Here are the headers I am including in the order I am including them:

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <wchar.h>
#include <wctype.h>

This is the line of code which gives me an error:

ret = __builtin_apply( (void *)swprintf, args, 1024 );

This is the error I get. Its the only error I get:

456: error: ‘swprintf’ undeclared (first use in this function)
456: error: (Each undeclared identifier is reported only once
456: error: for each function it appears in.)

In the NetBeans IDE, I right click the function name "swprintf" and click "Navigate / Go to Definition". It takes me to line 602 of "wchar.h":

/* Write formatted output of at most N characters to S.  */
extern int swprintf (wchar_t *__restrict __s, size_t __n,
		     __const wchar_t *__restrict __format, ...)
     __THROW /* __attribute__ ((__format__ (__wprintf__, 3, 4))) */;

So curiously enough, NetBeans can see it just fine. Why can't gcc? Remember, all the other wchar_t functions did not have any compiler errors. Also keep in mind that this is not a linker error.

Any ideas?

How are you compiling in GCC? That error usually comes from not supplying the required libraries at compile time.

I will admit that I don't completely know my way around the NetBeans IDE as well as I should. This is the only meaningful line of code in the "Build" tab right before the error shows up:

gcc    -c -g -I/usr/include/freetype2/freetype -I/usr/include/freetype2 -I/usr/local/include/SDL -I../shared -MMD -MP -MF build/Debug/GNU-Linux-x86/_ext/819228780/iString.o.d -o build/Debug/GNU-Linux-x86/_ext/819228780/iString.o ../shared/iString.c

iString.c/h being the file name of my code containing the error.

There is nothing in the C compiler options menu for the current project in Netbeans which adds any new information to this problem. It has all the appropriate include folders:

/usr/include/freetype2/freetype
/usr/include/freetype2
/usr/local/include/SDL
../shared

shared being where my code is located.

Here are the libraries I am linking at link time. I highly doubt that the linker is involved here:

GLU
GLUT
FreeType
SDL
SDLmain

So its basically OpenGL and its helper library, the FreeType library, and the SDL interface library.

If I haven't answered your question completely enough, please help me find that information for you in NetBeans. I can provide screenshots if that is helpful.

I will admit that I don't completely know my way around the NetBeans IDE as well as I should. This is the only meaningful line of code in the "Build" tab right before the error shows up:

gcc    -c -g -I/usr/include/freetype2/freetype -I/usr/include/freetype2 -I/usr/local/include/SDL -I../shared -MMD -MP -MF build/Debug/GNU-Linux-x86/_ext/819228780/iString.o.d -o build/Debug/GNU-Linux-x86/_ext/819228780/iString.o ../shared/iString.c

iString.c/h being the file name of my code containing the error.

There is nothing in the C compiler options menu for the current project in Netbeans which adds any new information to this problem. It has all the appropriate include folders:

/usr/include/freetype2/freetype
/usr/include/freetype2
/usr/local/include/SDL
../shared

shared being where my code is located.

Here are the libraries I am linking at link time. I highly doubt that the linker is involved here:

GLU
GLUT
FreeType
SDL
SDLmain

So its basically OpenGL and its helper library, the FreeType library, and the SDL interface library.

If I haven't answered your question completely enough, please help me find that information for you in NetBeans. I can provide screenshots if that is helpful.

Agree with you that it doesnt seem to be a linker issue
Which gcc version you are using?

My first post mentioned the version of gcc I was using, but here it is again written a different way:

[b]bash:~$[/b] gcc --version
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

My first post mentioned the version of gcc I was using, but here it is again written a different way:

[b]bash:~$[/b] gcc --version
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

My mistake.. i dint notice it..
Ok, Is this function definition protected by some macros???
Anyways try reading this link..
mite provide some help

EDIT: Also in my header file i dont see that 'extern' keywork in front of swprintf()
I am using mingw...
It could mean that your c library dont have the implementation... :S

Edited 6 Years Ago by sree_ec: n/a

Looking at "wchar.h", I notice this piece of code preceding the swprintf declaration as well as some other functions:

#if defined __USE_ISOC95 || defined __USE_UNIX98
__BEGIN_NAMESPACE_STD

I don't know how many nested preprocessor conditions are involved with that code, but either way, it seems I found a workaround to my problem....

My fix was as simple as appending the missing declaration to the top of my C code as shown here:

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <wchar.h>
#include <wctype.h>

/* Write formatted output of at most N characters to S.  */
extern int swprintf (wchar_t *__restrict __s, size_t __n,
		     __const wchar_t *__restrict __format, ...)
     __THROW /* __attribute__ ((__format__ (__wprintf__, 3, 4))) */;

Then I tested swprintf and it behaved as it should. Its strange that it was blocked in the first place. Well it doesn't matter now, as long as it works I'm happy.

This question has already been answered. Start a new discussion instead.