天天看點

Thrift編譯錯誤('::malloc' has not been declared)

問題版本:0.9.0

make[4]: Entering directory `/tmp/X/thrift-0.9.0/lib/cpp'

/bin/sh ../../libtool  --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I../..  -I/usr/local/thirdparty/boost/include -I./src -I./src/thrift -I/usr/local/thirdparty/openssl/include -Wall -g -O2 -MT Thrift.lo -MD -MP -MF .deps/Thrift.Tpo -c -o Thrift.lo `test -f 'src/thrift/Thrift.cpp' || echo './'`src/thrift/Thrift.cpp

libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I../.. -I/usr/local/thirdparty/boost/include -I./src -I./src/thrift -I/usr/local/thirdparty/openssl/include -Wall -g -O2 -MT Thrift.lo -MD -MP -MF .deps/Thrift.Tpo -c src/thrift/Thrift.cpp  -fPIC -DPIC -o .libs/Thrift.o

In file included from src/thrift/Thrift.cpp:22:

/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/cstdlib:119: error: '::malloc' has not been declared

/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/cstdlib:127: error: '::realloc' has not been declared

src/thrift/Thrift.cpp: In member function 'void apache::thrift::TOutput::printf(const char*, ...)':

src/thrift/Thrift.cpp:46: error: 'malloc' was not declared in this scope

make[4]: *** [Thrift.lo] Error 1

解決方法:

在成功執行configure後(在未執行configure之前找不到下列兩行),修改與configure同目錄下的config.h檔案,将檔案中的如下兩行注釋掉:

#define malloc rpl_malloc

#define realloc rpl_realloc

附1:安裝Thrift指令行:

./configure --prefix=/usr/local/thirdparty/thrift-0.9.0 --with-boost=/usr/local/thirdparty/boost --with-libevent=/usr/local/thirdparty/libevent CPPFLAGS="-I/usr/local/thirdparty/openssl/include" LDFLAGS="-ldl -L/usr/local/thirdparty/openssl/lib" --with-qt4=no --with-c_glib=no --with-csharp=no --with-erlang=no --with-perl=no --with-ruby=no --with-haskell=no --with-go=no --with-d

當OpenSSL未以預設安裝目錄時,請注意上面的用法。

附2:相關博文:

(安裝thrift時,注意openssl參數)http://blog.chinaunix.net/uid-20682147-id-3399150.html

如果在使用Thrift時,編譯遇到類似“TTransport.h:107: error: 'uint32_t' does not name a type”的錯誤,隻需要在Thrift.h檔案中增加一行:#include 。

Thrift.h檔案位于make install後的include目錄下,如果不知道在哪,可以使用find指令查找。