Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

undefined reference to `strdupa'

1,294 views
Skip to first unread message

Michelle Konzack

unread,
May 11, 2007, 2:12:39 PM5/11/07
to djgpp
Hello,

I have a simpel test program which schould split a Courier-Maildir in
its levels using:

----8<------------------------------------------------------------------
#include <stdio.h>
#include <string.h>
#include <stddef.h>

int main(int argc, char *argv[])
{
const char directory[] = ".ML_devel.djgpp@delorie_com.2007-04";
const char delimiter[] = ".";
char *result, *cp;

cp = strdupa(directory);

result = strtok(cp, delimiter);
printf("Result level 1 = %s\n", result);

result = strtok(NULL, delimiter);
printf("Result level 2 = %s\n", result);

result = strtok(NULL, delimiter);
printf("Result level 3 = %s\n", result);

result = strtok(NULL, delimiter);
printf("Result level 5 = %s\n", result);

return 0;
}
----8<------------------------------------------------------------------

but while compiling it with:

$ gcc -Wall -I/usr/include -o z_test z_test.c
z_test.c: In function 'main':
z_test.c:11: warning: implicit declaration of function 'strdupa'
z_test.c:11: warning: assignment makes pointer from integer without a cast
/tmp/michelle.konzack.r23246/ccSIU3aN.o: In function `main':
z_test.c:(.text+0x37): undefined reference to `strdupa'
collect2: ld returned 1 exit status

which is the first time I see this error. -- WHY?

Oh, I have this and other examples from a GNU-C Book and they are many
which are not working. (even with the provided original exanple files)

From the glibc documentation:

----[ "/usr/share/doc/glibc-doc/html/libc_5.html" ]---------------------
#include <paths.h>
#include <string.h>
#include <stdio.h>

const char path[] = _PATH_STDPATH;

int
main (void)
{
char *wr_path = strdupa (path);
char *cp = strtok (wr_path, ":");

while (cp != NULL)
{
puts (cp);
cp = strtok (NULL, ":");
}
return 0;
}
----8<------------------------------------------------------------------

Greetings
Michelle Konzack
sitting on the line...

--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack Apt. 917 ICQ #328449886
50, rue de Soultz MSN LinuxMichi
0033/6/61925193 67100 Strasbourg/France IRC #Debian (irc.icq.com)

signature.pgp

Robert Riebisch

unread,
May 14, 2007, 3:49:36 AM5/14/07
to
Michelle Konzack schrieb:

> $ gcc -Wall -I/usr/include -o z_test z_test.c
> z_test.c: In function 'main':
> z_test.c:11: warning: implicit declaration of function 'strdupa'
> z_test.c:11: warning: assignment makes pointer from integer without a cast
> /tmp/michelle.konzack.r23246/ccSIU3aN.o: In function `main':
> z_test.c:(.text+0x37): undefined reference to `strdupa'
> collect2: ld returned 1 exit status
>
> which is the first time I see this error. -- WHY?

DJGPP 2.03 or 2.04 does not have strdupa(). You need an updated Glibc.

--
Robert Riebisch
Bitte NUR in der Newsgroup antworten!
Please reply to the Newsgroup ONLY!

Michelle Konzack

unread,
May 14, 2007, 1:59:12 PM5/14/07
to djgpp
Forgotten to add:

#define _GNU_SOURCE

Greetings
Michelle Konzack
Systemadministrator
Tamay Dogan Network
Debian GNU/Linux Consultant

signature.pgp

Michelle Konzack

unread,
May 15, 2007, 12:41:08 PM5/15/07
to dj...@delorie.com
Am 2007-05-14 09:49:36, schrieb Robert Riebisch:
> DJGPP 2.03 or 2.04 does not have strdupa(). You need an updated Glibc.
>
------------------------- END OF REPLIED MESSAGE -------------------------

Hmmm, so it is NOT portable (Dos->Linux)...
Then I need another function. Grrr!

Greetings
Michelle Konzack

signature.pgp

Robert Riebisch

unread,
May 16, 2007, 4:54:50 AM5/16/07
to
Michelle Konzack schrieb:

> Hmmm, so it is NOT portable (Dos->Linux)...

It is portable. Just a matter of efforts.

0 new messages