I have already included string.h, I've even tried defining GNU
but I still get the same warning/error when I compile it.

below is not really code, its the warning/error I get

bravo:~/60-141/Assignment/Assignment3>cc assign3.c
"assign3.c", line 94: warning: implicit function declaration: strndup
Undefined                       first referenced
 symbol                             in file
strndup                             assign3.o
ld: fatal: Symbol referencing errors. No output written to a.out

This is my include
#define _GNU_SOURCE
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>

I tried it with and without
#define _GNU_SOURCE
it still doesnt work

but when I compile it with gcc from ubuntu. It works like a charm. no problem whatsoever.

Can anyone tell me how to fix this problem?(I think the compiler that had the problem is gcc, its the server from university of WIndsor)

Without seeing what you are doing in assign3.c, this is not helpful. Also, what compiler (include version) and platform are you building on?

Without seeing what you are doing in assign3.c, this is not helpful. Also, what compiler (include version) and platform are you building on?

The program is 600 lines long. I dont think it would make any difference to read it anyway. The impmlementation is perfect. The trouble is that the compiler doesnt recognize strndup.

my compiler is gcc 4.4.5
from terminal
efron@Caladbolg:~/Desktop/60-141/Assignment/Assignment3$ gcc --version
gcc-4.4.real (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
Copyright (C) 2010 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.

the server compiler is gcc 4.3 if Im not mistaken.

I looked around and ended up with the same information that you did, but read this http://cboard.cprogramming.com/c-programming/55152-trouble-strndup-function.html (especially the post from Salem) about the compiler switch -ansi being incompatible with the non-standard functions (you don't use any switches in your example above, but I didn't know if the server had a different setup)).

If you go into your schools include directory, you can open their string.h and make sure the declaration is actually in there (I don't remember the directory structure on *nix, I think it's something like /usr/local/include, but don't quote me on that).

Failing all that, as the thread also recommends, you could roll your own out of standard library functions.

P.S. It's not very polite to bump your thread

Im sorry my deadline is today at midnight so I need to get some answer fast. so sorry again. Its not like Im going to bump it a lot of times, btw Im closing this thread, it seems the GAs here said that strndup is not a standard library function. Its only available in some compilers. So they gave me an link to the ubuntu server instead of solaris. Now its working perfectly. btw thanks for answering. :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.