想将peep2k的web failsafe http移植到mt7620的uboot中,但是出现了undefined reference to `strstr'的错误!
console输出如下:
net/libnet.a(httpd.o): In function `httpd_findandstore_firstchunk':
uip-0.9/httpd.c:(.text+0x90): undefined reference to `strstr'
uip-0.9/httpd.c:(.text+0xa8): undefined reference to `strstr'
uip-0.9/httpd.c:(.text+0xd4): undefined reference to `strstr'
uip-0.9/httpd.c:(.text+0x108): undefined reference to `strstr'
uip-0.9/httpd.c:(.text+0x14c): undefined reference to `strstr'
分析:
该错误出现在链接阶段,说明提供strstr函数的方法最终没有被编译进目标文件。很显然,strstr函数出现在string.c源文件中,问题在哪里呢?
于是打开string.c文件,发现了其中的奥秘!
#ifndef __HAVE_ARCH_STRSTR
/**
* strstr - Find the first substring in a %NUL terminated string
* @s1: The string to be searched
* @s2: The string to search for
*/
char * strstr(const char * s1,const char * s2)
{
int l1, l2;
l2 = strlen(s2);
if (!l2)
return (char *) s1;
l1 = strlen(s1);
while (l1 >= l2) {
l1--;
if (!memcmp(s1,s2,l2))
return (char *) s1;
s1++;
}
return NULL;
}
#endif
#ifndef __HAVE_ARCH_STRSTR
如果没有定义__HAVE_ARCH_STRSTR,则编译strstr!再看看文件前部的关于这个宏的定义,就豁然开朗了。
/* in order to save flash space, we declare below definition here.
* please modify it if you need below function */
#define __HAVE_ARCH_STRNICMP
#define __HAVE_ARCH_STRNICMP
#define __HAVE_ARCH_STRCPY
#define __HAVE_ARCH_STRNCPY
#define __HAVE_ARCH_STRCAT
#define __HAVE_ARCH_STRNCAT
#define __HAVE_ARCH_STRCMP
#define __HAVE_ARCH_STRNCMP
#define __HAVE_ARCH_STRDUP
#define __HAVE_ARCH_STRSPN
#define __HAVE_ARCH_STRPBRK
#define __HAVE_ARCH_STRTOK
#define __HAVE_ARCH_STRSEP
#define __HAVE_ARCH_STRSWAB
#define __HAVE_ARCH_BCOPY
#define __HAVE_ARCH_MEMSCAN
#define __HAVE_ARCH_STRSTR
#define __HAVE_ARCH_MEMCHR
看看上面的英文注释,应该明白是怎么回事了吧,注释掉相应的宏就可以了!