抱歉,评论被关闭
Sphinx 编译的问题及解决办法(sphinxclient.c:1358: error: ‘SO_NOSIGPIPE’ undeclared)
编译sphinx库 —-libsphinxclient遇到的错误如下:
A错误: sphinxclient.c:1358: error: ‘SO_NOSIGPIPE’ undeclared (first use in this function)
B错误: .libs/libsphinxclient.a(sphinxclient.o): In function `vi sphinxclient.cset_error’:
解决这两个问题都需要修改sphinxclient.c 文件,如下所示:
A错误详细表述:
[root@localhost libsphinxclient]# make
make all-am
make[1]: Entering directory `/usr/local/src/sphinx-1.10-beta/api/libsphinxclient’
/bin/sh ./libtool –mode=compile –tag=CC gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c -o
sphinxclient.lo sphinxclient.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c sphinxclient.c -fPIC -DPIC -o .libs/sphinxclient.o
sphinxclient.c: In function ‘net_connect_get’:
sphinxclient.c:1358: error: ‘SO_NOSIGPIPE’ undeclared (first use in this function)
sphinxclient.c:1358: error: (Each undeclared identifier is reported only once
sphinxclient.c:1358: error: for each function it appears in.)
make[1]: *** [sphinxclient.lo] 错误 1
make[1]: Leaving directory `/usr/local/src/sphinx-1.10-beta/api/libsphinxclient’
make: *** [all] 错误 2
A错误解决方法一:SO_NOSIGPIPE 改为 0 (编译通过了 ,但是在运行程序的时候,ERROR: setsockopt() failed: Protocol not available . 所以此方法不得行,抛弃,有需要重新编译,抓狂!)
A错误解决方法二:
红色表明为更改内容
#ifndef _WIN32
if ( setsockopt ( sock, SOL_SOCKET, SO_NOSIGPIPE, (void *)&optval, (socklen_t)sizeof(optval) ) <
0 )
{
set_error ( client, “setsockopt() failed: %s”, sock_error() );
return -1;
}
#endif
改为
#if defined(SO_NOSIGPIPE)
if ( setsockopt ( sock, SOL_SOCKET, SO_NOSIGPIPE, (void *)&optval, (socklen_t)sizeof(optval) ) <
0 )
{
set_error ( client, “setsockopt() failed: %s”, sock_error() );
return -1;
}
#endif
B错误详细表述:
[root@localhost libsphinxclient]# make
make all-am
make[1]: Entering directory `/data/www/api/libsphinxclient’
/bin/sh ./libtool –tag=CC –mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c -o
sphinxclient.lo sphinxclient.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c sphinxclient.c -fPIC -DPIC -o .libs/sphinxclient.o
gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c sphinxclient.c -o sphinxclient.o >/dev/null 2>&1
/bin/sh ./libtool –tag=CC –mode=link gcc -g -O2 -o libsphinxclient.la -rpath /usr/local/lib -release
0.0.1 sphinxclient.lo
rm -fr .libs/libsphinxclient-0.0.1.so .libs/libsphinxclient.a .libs/libsphinxclient.la
.libs/libsphinxclient.lai .libs/libsphinxclient.so
gcc -shared .libs/sphinxclient.o -Wl,-soname -Wl,libsphinxclient-0.0.1.so -o .libs/libsphinxclient-
0.0.1.so
(cd .libs && rm -f libsphinxclient.so && ln -s libsphinxclient-0.0.1.so libsphinxclient.so)
ar cru .libs/libsphinxclient.a sphinxclient.o
ranlib .libs/libsphinxclient.a
creating libsphinxclient.la
(cd .libs && rm -f libsphinxclient.la && ln -s ../libsphinxclient.la libsphinxclient.la)
/bin/sh ./libtool –tag=CC –mode=link gcc -g -O2 -o test test.o .libs/libsphinxclient.a
gcc -g -O2 -o test test.o .libs/libsphinxclient.a
.libs/libsphinxclient.a(sphinxclient.o): In function `set_error’:
/data/www/api/libsphinxclient/sphinxclient.c:359: undefined reference to `_vsnprintf’
collect2: ld returned 1 exit status
make[1]: *** [test] 错误 1
B错误解决办法 #define vsnprintf _vsnprintf 改为//define vsnprintf _vsnprintf (注释掉了)
本文出自 “凹凸曼” 博客,请务必保留此出处 http://www.apoyl.com/?p=300