LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-10-2010, 02:57 AM   #1
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Question undefined reference to `stricmp'


junk.c
Code:
#include <string.h>

int main ()
{
     stricmp ("anisha", "kaul");
     return 0;
}
Code:
anisha@linux-uitj:~> gcc junk.c -Wall -Wextra
junk.c: In function ‘main’:
junk.c:5: warning: implicit declaration of function ‘stricmp’
/tmp/ccUhL95d.o: In function `main':
junk.c:(.text+0x14): undefined reference to `stricmp'
collect2: ld returned 1 exit status
The man page: http://www.qnx.com/developers/docs/6...s/stricmp.html
says it is in string.h, HELP!

Last edited by Aquarius_Girl; 12-10-2010 at 03:30 AM.
 
Old 12-10-2010, 03:37 AM   #2
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
Try using instead strncasecmp()
 
1 members found this post helpful.
Old 12-10-2010, 03:42 AM   #3
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Well, strncasecmp worked, thanks for that, but I am still wondering what happened to stricmp ???
 
Old 12-10-2010, 05:49 AM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
The link you gave us pointed to a QNX man page. QNX is not Linux; you have shown us that QNX offers a function, stricmp(), which is not part of the POSIX standard.
 
1 members found this post helpful.
Old 12-10-2010, 09:55 AM   #5
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Rep: Reputation: 5
Quote:
Originally Posted by anishakaul View Post
junk.c
Code:
#include <string.h>

int main ()
{
     stricmp ("anisha", "kaul");
     return 0;
}
Code:
anisha@linux-uitj:~> gcc junk.c -Wall -Wextra
junk.c: In function ‘main’:
junk.c:5: warning: implicit declaration of function ‘stricmp’
/tmp/ccUhL95d.o: In function `main':
junk.c:(.text+0x14): undefined reference to `stricmp'
collect2: ld returned 1 exit status
The man page: http://www.qnx.com/developers/docs/6...s/stricmp.html
says it is in string.h, HELP!
If it were nt inside string.h, it should hv been a compiler error you were getting instead of linker error.
So you can look whether the definition is inside some Compiler directive[macros]
 
0 members found this post helpful.
Old 12-10-2010, 04:55 PM   #6
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
Quote:
If it were nt inside string.h, it should hv been a compiler error
He got compiler warning first.
Quote:
junk.c:5: warning: implicit declaration of function ‘stricmp’
This means that function has not been declared ealier (even in string.h) and compiler did it automagically - but this was not been intention of programmer.
 
2 members found this post helpful.
Old 12-12-2010, 09:01 PM   #7
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by sree_ec View Post
If it were nt inside string.h, it should hv been a compiler error you were getting instead of linker error.
So you can look whether the definition is inside some Compiler directive[macros]
Okay, look at the following code, I ve added another function:
junk.c
Code:
#include <string.h>

int main ()
{
     stricmp ("sad", "sdsa");
     unknown ();
     return 0;
}
Output:
Code:
anisha@linux-uitj:~> gcc junk.c -Wall -Wextra
junk.c: In function ‘main’:
junk.c:5: warning: implicit declaration of function ‘stricmp’
junk.c:6: warning: implicit declaration of function ‘unknown’
/tmp/cc8TuWnE.o: In function `main':
junk.c:(.text+0x14): undefined reference to `stricmp'
junk.c:(.text+0x1e): undefined reference to `unknown'
collect2: ld returned 1 exit status
Now whatdoyou say

Quote:
Originally Posted by eSelix View Post
She got compiler warning first.
 
Old 12-12-2010, 09:31 PM   #8
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by wje_lq View Post
The link you gave us pointed to a QNX man page. QNX is not Linux; you have shown us that QNX offers a function, stricmp(), which is not part of the POSIX standard.
Thanks for pointing that out!
Now I looked up Goooooo to find out this:
Quote:
QNX is a commercial Unix-like real-time operating system, aimed primarily at the embedded systems market.
Secondly, I looked up /usr/src/linux-2.6.31.5-0.1/include/linux/string.h

I saw there a function named: strnicmp, which is not much different from stricmp!

Is there any link which contains all Posix standard functions?

Last edited by Aquarius_Girl; 12-12-2010 at 10:32 PM. Reason: made a new post for the edits
 
Old 12-12-2010, 10:36 PM   #9
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
I found this: http://en.wikipedia.org/wiki/String.h

Here strnicmp is missing in that link but it is present in string.h in my computer with OpenSuse 11.2 with the following declaration:
extern int strnicmp(const char *, const char *, __kernel_size_t);

Code:
#include <string.h>

int main ()
{
     strnicmp ("anisha", "kaul");
     return 0;
}
Code:
anisha@linux-uitj:~> gcc junk.c -Wall -Wextra
junk.c: In function ‘main’:
junk.c:5: warning: implicit declaration of function ‘strnicmp’
/tmp/ccI5NoIs.o: In function `main':
junk.c:(.text+0x14): undefined reference to `strnicmp'
collect2: ld returned 1 exit status
Code:
anisha@linux-uitj:~> man strnicmp

STRNICMP(9)                            Basic C Library Functions                           STRNICMP(9)



NAME
       strnicmp - Case insensitive, length-limited string comparison

SYNOPSIS
       int strnicmp(const char * s1, const char * s2, size_t len);

ARGUMENTS
       s1
           One string

       s2
           The other string

       len
           the maximum number of characters to compare

COPYRIGHT
Kernel Hackers Manual 2.6.

Last edited by Aquarius_Girl; 12-12-2010 at 10:37 PM.
 
Old 12-12-2010, 10:45 PM   #10
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
In the name of the Flying Spaghetti Monster,

You could return to google and search for "standard POSIX functions". That yields two very useful links near the top of the search, to wikipedia articles entitled "POSIX" and "C POSIX library". Browse through both of those; the second one contains this very useful link.
 
1 members found this post helpful.
Old 12-12-2010, 10:50 PM   #11
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by anishakaul View Post
it is present in string.h in my computer with OpenSuse 11.2[/I][/U] with the following declaration:
extern int strnicmp(const char *, const char *, __kernel_size_t);
Hmmmm. "Present". You use that term. I do not think it means what you think it means. Is that line surrounded by any conditional compilation directives which end up excluding it?

Here's a test, if it's in fact your computer: Change that line in string.h so it says:
Code:
exxtern int strnicmp(const char *, const char *, __kernel_size_t);
That's right. Put an extra x in there. If your code still compiles, then this line was excluded by conditional compilation directives, so the compiler didn't care about that extra x. (Be sure to change it back, just because leaving a mess is not a good idea.)
 
1 members found this post helpful.
Old 12-12-2010, 10:56 PM   #12
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731

Original Poster
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by wje_lq View Post
Hmmmm. "Present". You use that term. I do not think it means what you think it means. Is that line surrounded by any conditional compilation directives which end up excluding it?
Thanks again for the useful link and comments! I don't know what has that monster to do with all this?? You write it most often, it is because the question was dumb?

I have attached the string.h and bolded the relevant text. I'll try out your way but why is the man page there then?

Code:
#ifndef _LINUX_STRING_H_
#define _LINUX_STRING_H_

/* We don't want strings.h stuff being used by user stuff by accident */

#ifndef __KERNEL__
#include <string.h>
#else

#include <linux/compiler.h>	/* for inline */
#include <linux/types.h>	/* for size_t */
#include <linux/stddef.h>	/* for NULL */
#include <stdarg.h>

extern char *strndup_user(const char __user *, long);
extern void *memdup_user(const void __user *, size_t);

/*
 * Include machine specific inline routines
 */
#include <asm/string.h>

#ifndef __HAVE_ARCH_STRCPY
extern char * strcpy(char *,const char *);
#endif
#ifndef __HAVE_ARCH_STRNCPY
extern char * strncpy(char *,const char *, __kernel_size_t);
#endif
#ifndef __HAVE_ARCH_STRLCPY
size_t strlcpy(char *, const char *, size_t);
#endif
#ifndef __HAVE_ARCH_STRCAT
extern char * strcat(char *, const char *);
#endif
#ifndef __HAVE_ARCH_STRNCAT
extern char * strncat(char *, const char *, __kernel_size_t);
#endif
#ifndef __HAVE_ARCH_STRLCAT
extern size_t strlcat(char *, const char *, __kernel_size_t);
#endif
#ifndef __HAVE_ARCH_STRCMP
extern int strcmp(const char *,const char *);
#endif
#ifndef __HAVE_ARCH_STRNCMP
extern int strncmp(const char *,const char *,__kernel_size_t);
#endif
#ifndef __HAVE_ARCH_STRNICMP
extern int strnicmp(const char *, const char *, __kernel_size_t);
#endif
#ifndef __HAVE_ARCH_STRCASECMP
extern int strcasecmp(const char *s1, const char *s2);
#endif
#ifndef __HAVE_ARCH_STRNCASECMP
extern int strncasecmp(const char *s1, const char *s2, size_t n);
#endif
#ifndef __HAVE_ARCH_STRCHR
extern char * strchr(const char *,int);
#endif
#ifndef __HAVE_ARCH_STRNCHR
extern char * strnchr(const char *, size_t, int);
#endif
#ifndef __HAVE_ARCH_STRRCHR
extern char * strrchr(const char *,int);
#endif
extern char * strstrip(char *);
#ifndef __HAVE_ARCH_STRSTR
extern char * strstr(const char *,const char *);
#endif
#ifndef __HAVE_ARCH_STRLEN
extern __kernel_size_t strlen(const char *);
#endif
#ifndef __HAVE_ARCH_STRNLEN
extern __kernel_size_t strnlen(const char *,__kernel_size_t);
#endif
#ifndef __HAVE_ARCH_STRPBRK
extern char * strpbrk(const char *,const char *);
#endif
#ifndef __HAVE_ARCH_STRSEP
extern char * strsep(char **,const char *);
#endif
#ifndef __HAVE_ARCH_STRSPN
extern __kernel_size_t strspn(const char *,const char *);
#endif
#ifndef __HAVE_ARCH_STRCSPN
extern __kernel_size_t strcspn(const char *,const char *);
#endif

#ifndef __HAVE_ARCH_MEMSET
extern void * memset(void *,int,__kernel_size_t);
#endif
#ifndef __HAVE_ARCH_MEMCPY
extern void * memcpy(void *,const void *,__kernel_size_t);
#endif
#ifndef __HAVE_ARCH_MEMMOVE
extern void * memmove(void *,const void *,__kernel_size_t);
#endif
#ifndef __HAVE_ARCH_MEMSCAN
extern void * memscan(void *,int,__kernel_size_t);
#endif
#ifndef __HAVE_ARCH_MEMCMP
extern int memcmp(const void *,const void *,__kernel_size_t);
#endif
#ifndef __HAVE_ARCH_MEMCHR
extern void * memchr(const void *,int,__kernel_size_t);
#endif

extern char *kstrdup(const char *s, gfp_t gfp);
extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
extern void *kmemdup(const void *src, size_t len, gfp_t gfp);

extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
extern void argv_free(char **argv);

extern bool sysfs_streq(const char *s1, const char *s2);

#ifdef CONFIG_BINARY_PRINTF
int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args);
int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf);
int bprintf(u32 *bin_buf, size_t size, const char *fmt, ...) __printf(3, 4);
#endif

extern ssize_t memory_read_from_buffer(void *to, size_t count, loff_t *ppos,
			const void *from, size_t available);

/**
 * strstarts - does @str start with @prefix?
 * @str: string to examine
 * @prefix: prefix to look for.
 */
static inline bool strstarts(const char *str, const char *prefix)
{
	return strncmp(str, prefix, strlen(prefix)) == 0;
}
#endif
#endif /* _LINUX_STRING_H_ */

Last edited by Aquarius_Girl; 12-12-2010 at 11:32 PM. Reason: typo
 
Old 12-12-2010, 11:43 PM   #13
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
In the name of the Flying Spaghetti Monster,

Here's your trouble. You're probably not including string.h, but rather strings.h. I'm glad you're posting its content; see this part?

Code:
/* We don't want strings.h stuff being used by user stuff by accident */

#ifndef __KERNEL__
#include <string.h>
#else
If in fact you're including strings.h, those lines in that file correct the error for you, and nothing else (see that else?) in the file will be accessible to you, including strnicmp.
Quote:
Originally Posted by anishakaul View Post
why is the man page there then?
Excellent question. If you posted the entire man page, it omits a very important section: the CONFORMING TO section. Does your man page for strncasecmp have such a section? There's one in Debian's man page:
Code:
CONFORMING TO
       4.4BSD, POSIX.1-2001.
Quote:
Originally Posted by anishakaul View Post
I don't know what has that monster to do with all this??
Happy to enlighten you. First, read all about the Flying Spaghetti Monster here. I started invoking its name after another poster, in asking a question, began his question in the name of Allah. Someone else objected, and a moderator stepped in, saying that we shouldn't be "making religious statements" in our posts. The moderator locked the thread. I suspect there's a certain amount of unintentional bias here, because nobody seems to be disciplined because of including (Christian) Bible quotations in his signature. I raised the issue with the moderator, asking whether we were going to be consistent, and got no answer. So I'm using this greeting to establish a precedent. Maybe they'll discipline me with ten lashes with a wet piece of spaghetti or something. (The normal English idiom for ridiculously mild punishment would be "ten lashes with a wet noodle".) For more information, go here and here and here.
 
1 members found this post helpful.
Old 12-13-2010, 05:36 PM   #14
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
Quote:
Originally Posted by anishakaul View Post
She got compiler warning first.
Sorry Anisha I second time mistake someone gender. There should be some kind of sex mark near the nick.




Quote:
Okay, look at the following code, I ve added another function:
junk.c
Code:
#include <string.h>

int main ()
{
     stricmp ("sad", "sdsa");
     unknown ();
     return 0;
}
Now whatdoyou say
I could say the same as ealier But I try to say that otherwise. In C every undeclared function, like unknown() and stricmp() is automaticaly declared during first occurrence by the compiler. It is declared but anywhere defined. So compiler generate a warning (implicit declaration of function) and linker an error (undefined reference to).

You can get better error handling if you use C++. It has more strict syntax. In your example it will generate compiler error just where is stricmp() that it wasn't anywhere declared.
 
Old 12-14-2010, 06:05 AM   #15
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Rep: Reputation: 5
Quote:
Originally Posted by anishakaul View Post
Okay, look at the following code, I ve added another function:
junk.c
Code:
#include <string.h>

int main ()
{
     stricmp ("sad", "sdsa");
     unknown ();
     return 0;
}
Output:
Code:
anisha@linux-uitj:~> gcc junk.c -Wall -Wextra
junk.c: In function ‘main’:
junk.c:5: warning: implicit declaration of function ‘stricmp’
junk.c:6: warning: implicit declaration of function ‘unknown’
/tmp/cc8TuWnE.o: In function `main':
junk.c:(.text+0x14): undefined reference to `stricmp'
junk.c:(.text+0x1e): undefined reference to `unknown'
collect2: ld returned 1 exit status
Now whatdoyou say
I believe she was trying to correct me. Thank you anisha...Accepted. I did not pay much attention.
 
1 members found this post helpful.
  


Reply

Tags
stricmp



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined reference, why? george_mercury Programming 4 05-07-2009 12:15 AM
undefined reference to.... crapodino Programming 1 01-13-2008 07:05 PM
undefined reference to... dimah Programming 3 12-27-2006 09:57 AM
undefined reference vkmgeek Programming 1 05-11-2006 06:37 AM
Undefined Reference ChemicalBurn Programming 2 02-14-2005 03:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration