apache 错误:未在此范围中声明“strdup”

htzpubme  于 2023-02-24  发布在  Apache
关注(0)|答案(4)|浏览(198)

我正在尝试构建和安装Apache Thrift编译器和库
如说明所示,运行./configure && make
我得到了这个错误:

thrift 0.9.3

Building C++ Library ......... : no
Building C (GLib) Library .... : no
Building Java Library ........ : no
Building C# Library .......... : no
Building Python Library ...... : no
Building Ruby Library ........ : no
Building Haxe Library ........ : no
Building Haskell Library ..... : no
Building Perl Library ........ : no
Building PHP Library ......... : no
Building Erlang Library ...... : no
Building Go Library .......... : no
Building D Library ........... : no
Building NodeJS Library ...... : no
Building Lua Library ......... : no

If something is missing that you think should be present,
please skim the output of configure to find the missing
component.  Details are present in config.log.
make  all-recursive
make[1]: Entering directory '/c/University/InternetOfThings/thrift-0.9.3'
Making all in compiler/cpp
make[2]: Entering directory '/c/University/InternetOfThings/thrift-0.9.3/compiler/cpp'
/bin/sh ../../ylwrap src/thrifty.yy y.tab.c src/thrifty.cc y.tab.h `echo src/thrifty.cc | sed -e s/cc$/hh/ -e s/cpp$/hpp/ -e s/cxx$/hxx/ -e s/c++$/h++/ -e s/c$/h/` y.output src/thrifty.output -- bison -y -d
updating src/thrifty.hh
make  all-am
make[3]: Entering directory '/c/University/InternetOfThings/thrift-0.9.3/compiler/cpp'
g++ -DHAVE_CONFIG_H -I. -I../.. -I../../lib/cpp/src/thrift  -I./src  -Wall -Wno-sign-compare -Wno-unused -g -O2 -std=c++11 -MT src/libparse_a-thrifty.o -MD -MP -MF src/.deps/libparse_a-thrifty.Tpo -c -o src/libparse_a-thrifty.o `test -f 'src/thrifty.cc' || echo './'`src/thrifty.cc
src/thrifty.yy: In function 'int yyparse()':
src/thrifty.yy:1311:30: error: 'strdup' was not declared in this scope
Makefile:912: recipe for target 'src/libparse_a-thrifty.o' failed
make[3]: *** [src/libparse_a-thrifty.o] Error 1
make[3]: Leaving directory '/c/University/InternetOfThings/thrift-0.9.3/compiler/cpp'
Makefile:588: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/c/University/InternetOfThings/thrift-0.9.3/compiler/cpp'
Makefile:609: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/c/University/InternetOfThings/thrift-0.9.3'
Makefile:530: recipe for target 'all' failed
make: *** [all] Error 2

我编辑了thrifty. yy并添加了#include <string.h>,但仍然得到了strdup缺失的相同错误。
src/thrifty.yy:1311:30: error: 'strdup' was not declared in this scope(与之前相同的错误,包括字符串. h)
我错过了什么?
先谢了!

41zrol4v

41zrol4v1#

strdup不是一个标准的C函数。当编译器被配置为严格的C兼容时,它不允许在标准库头文件(如<string.h>)中转储自己的自定义、非标准函数。
您可以通过更改编译器来编译非标准C代码(例如在gcc中,使用-std=gnu11而不是-std=c11编译),或者坚持使用纯标准C来解决这个问题。
...或者只是自己实现strdup,都很简单:

#include <string.h>
#include <stdlib.h>

char* strdup (const char* s)
{
  size_t slen = strlen(s);
  char* result = malloc(slen + 1);
  if(result == NULL)
  {
    return NULL;
  }

  memcpy(result, s, slen+1);
  return result;
}
wvyml7n5

wvyml7n52#

在我的示例中,在MakeFile中,按目录/thrift-x.x.x/compiler/cpp/src-std=c++11替换为-std=gnu++11

wgeznvg7

wgeznvg73#

./配置CXXFLAGS ='-标准配置=gnu++11'并生成

8xiog9wr

8xiog9wr4#

src/储蓄/运输/THttp服务器.cpp:在成员函数“虚拟无效apache::thrift::transport::THttpServer::解析头(char*)”中:源代码/存储器/传输/THttp服务器。cpp:51:47:错误:未在此范围中声明“strcasestr”;你的意思是“strcasecmp”吗?|#define THRIFT_strcasestr(干草堆,针)strcasestr(干草堆,针)|^~~~~~~~~ src/存储器/传输/THttp服务器.cpp:63:9:注意:在宏“THRIFT_strcasestr”63的扩展中|如果(THRIFT_strcasestr(值,“已分块”)!=空指针){
有什么想法吗?

相关问题