移植uip-0.9到u-boot中出现undefined reference to `strstr'错误的解决过程

想将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

看看上面的英文注释,应该明白是怎么回事了吧,注释掉相应的宏就可以了!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值