2016-11-23 60 views
1

我試圖建立和安裝Apache節儉編譯器和庫錯誤:「的strdup」在此範圍

未聲明如圖指令運行./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(同樣的錯誤,包括string.h中之前)

缺少什麼我在這裏?

在此先感謝!

+0

http://stackoverflow.com/questions/32944390/what-is -the-ration-for-not-including-str-c-in-the-c-standard – Steephen

+0

config.log中的任何相關內容? – JensG

+0

那是cygwin的環境嗎? Woudl很高興知道......在這種情況下,請查看[THRIFT-2800](https://issues.apache.org/jira/browse/THRIFT-2800) – JensG

回答

2

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; 
} 
+0

將'strdup'的實現添加到'thrifty.yy'給出了更多的錯誤: '0.9.3/compiler/cpp/src/thrifty.yy:255.5:error:invalid character:'*' char * strdup const char * s) /c/University/InternetOfThings/thrift-0.9.3/compiler/cpp/src/thrifty.yy:255.14:error:invalid character:'(' char * strdup(const char * s) 我想它是一個C++編譯器,所以它不會識別指針 如何更改編譯器以編譯非標準C代碼 –

+1

@TonyTannous不要使用C++編譯器編譯C代碼,沒有理由爲什麼C++編譯器不會識別指針,更有可能它不識別''但給出了錯誤的錯誤。 – Lundin

+0

這不是我,我所做的只是按照說明中的./configure && make。 https://thrift.apache.org/tutorial/ –