Error compiling Thrift Server

I am new to Thrift: http://thrift.apache.org/ I am using CentOS and possibly “successfully installing Thrift”. I can use thrift to generate codes. But follow the instructions: http://wiki.apache.org/thrift/ThriftUsageC%2B%2B I get an error compiling Something_server.cpp Someone knows that pls helps me find out the reason. I have no idea. Thank you very much

I use thrift so that PHP can call C ++ to do a job that only C ++ can do. Anyone have any other suggestion for me? thank you

[root @localhost gen-cpp] # g ++ -Wall -I / usr / local / include / thrift * .cpp -lthrift -o something /usr/local/include/thrift/protocol/TBinaryProtocol.tcc: In function- âuint32_t apache member :: thrift :: protocol :: TBinaryProtocolT :: writeI16 (int16_t) â: /usr/local/include/thrift/protocol/TBinaryProtocol.tcc:147: error: there are no arguments for âhtonsâ that depend on the template parameter, therefore, the declaration âhtonsâ /usr/local/include/thrift/protocol/TBinaryProtocol.tcc:147 should be available: error: (if you use â-fpermissiveâ, g ++ will accept your code but allow the use of an undeclared name is outdated) / usr / local / include / thrift / protocol / TBinaryProtocol.tcc: In the âuint32_t apache member function :: thrift :: protocol :: TBinaryProtocolT :: writeI32 (int32_t) â: / usr / loc al / include / thrift / protocol / TBinaryProtocol.tcc: 154: error: no arguments for âhtonlâ that depend on the template parameter, so âhtonlâ Something_server.cpp declaration should be available: In the âvirtual int32_t SomethingHandler :: ping () â member function : Something_server.cpp: 28: warning: no return in function returning non-void /usr/local/include/thrift/protocol/TBinaryProtocol.tcc: In âuint32_t member function apache :: thrift :: protocol :: TBinaryProtocolT :: writeI16 (int16_t) [with Transport_ = apache :: thrift :: transport :: TTransport] â: /usr/local/include/thrift/protocol/TVirtualProtocol.h:401: instance from âuint32_t apache :: thrift :: protocol :: TVirtualProtocol :: writeI16_virt (int16_t) [with Protocol_ = apache :: thrift :: protocol :: TBinaryProtocolT, Super_ = apache: : thrift :: protocol :: TProtocolDefaults] â Something_server.cpp: 42: created here /usr/local/include/thrift/protocol/TBinaryProtocol.tcc:147: error: âhtonsâ was not declared in this area / usr / local / include /thrift/protocol/TBinaryProtocol.tcc: In the âuint32_t apache member function :: thrift :: protocol :: TBinaryProtocolT :: writeI32 (int32_t) [with Transport_ = apache :: thrift :: transport :: TTransport] â: / usr / local / include / thrift / protocol / TVirtualProtocol.h: 405: instance from âuint32_t apache :: thrift :: protocol :: TVirtualProtocol :: writeI32_virt (int32_t) [with Protocol_ = apache :: thrift :: protocol :: TBinaryProtocolT, Super_ = apache :: thrift :: protocol :: TProtocolDefaults] â Something_server.cpp: 42: created here /usr/local/include/thrift/protocol/TBinaryProtocol.tcc:154: error: âhtonlâ was not declared in this area / usr / local / include / t hrift / protocol / TBinaryProtocol.tcc: In the âuint32_t member function apache :: thrift :: protocol :: TBinaryProtocolT :: readI16 (int16_t &) [with Transport_ = apache :: thrift :: transport :: TTransport] A: / usr / local / include / thrift / protocol / TVirtualProtocol.h: 499: instance from âuint32_t apache :: thrift :: protocol :: TVirtualProtocol :: readI16_virt (int16_t &) [with Protocol_ = apache :: thrift :: protocol :: TBinaryProtocolT, Super_ = apache :: thrift :: protocol :: TProtocolDefaults] â Something_server.cpp: 42: created here /usr/local/include/thrift/protocol/TBinaryProtocol.tcchaps62: error: ântohsâ was not declared in this area / usr / local / include / thrift / protocol / TBinaryProtocol.tcc: In the âuint32_t apache member function :: thrift :: protocol :: TBinaryProtocolT :: readI32 (int32_t &) [with Transport_ = apache :: thrift :: transport :: TTransport] A : / usr / local / include / thrif t / protocol / TVirtualProtocol.h: 503: instance from âuint32_t apache :: thrift :: protocol :: TVirtualProtocol :: readI32_virt (int32_t &) [with Protocol_ = apache :: thrift :: protocol :: TBinaryProtocolT, Super_ = apache :: thrift :: protocol :: TProtocolDefaults] â Something_server.cpp: 42: created here /usr/local/include/thrift/protocol/TBinaryProtocol.tcchaps73: error: ântohlâ was not declared in this area / usr / local / include / thrift / protocol / TBinaryProtocol.tcc: In the âuint32_t apache member function :: thrift :: protocol :: TBinaryProtocolT :: writeI16 (int16_t) â: /usr/local/include/thrift/protocol/TBinaryProtocol.tcc:147: error: there are no arguments for âhtonsâ that depend on the template parameter, so the declaration âhtonsâ /usr/local/include/thrift/protocol/TBinaryProtocol.tcc:147 should be available: error: (if you use Using â-fpermissiveâ, g ++ will accept your code, but allowing the use of an undeclared name is outdated) / USR / local / enable / thrift / protocol / TBinaryProtocol.tcc: In the âuint32_t member function apache :: thrift :: protocol :: TBinaryProtocolT :: writeI32 (int32_t) â: /usr/local/include/thrift/protocol/TBinaryProtocol.tcc:154: error: there are no arguments for âhtonlâ that depend on the template parameter, so âhtonlâ Something_server.skeleton.cpp declaration should be available: In function- âvirtual int32_t member SomethingHandler :: ping () â: Something_server.skeleton.cpp: 28: warning: no return in function returning non-void /usr/local/include/thrift/protocol/TBinaryProtocol.tcc: In member function âuint32_t apache :: thrift :: protocol :: TBinaryProtocolT :: writeI16 (int16_t) [with Transport_ = apache :: thrift :: transport :: TTransport] â: /usr/local/include/thrift/protocol/TVirtualProtocol.hoors01 : instance from âuint32_t apache :: thrift :: protocol :: TVirtualProtocol :: writeI16_virt (int16_t) [with Protocol_ = apache :: thrift :: protocol :: TBinaryProtocolT, Super_ = apache :: thrift :: protocol :: TProtocolDefaults] â Something_server .skeleton.cpp: 42: created here /usr/local/include/thrift/protocol/TBinaryProtocol.tcc:147: error: âhtonsâ was not declared in this area /usr/local/include/thrift/protocol/TBinaryProtocol.tcc: In the âuint32_t member function apache :: thrift :: protocol :: TBinaryProtocolT :: writeI32 (int32_t) [with Transport_ = apache :: thrift :: transport :: TTransport] â: / usr / local / include / thrift / protocol / TVirtualProtocol .h: 405: instance and âuint32_t apache :: thrift :: protocol :: TVirtualProtocol :: writeI32_virt (int32_t) [with Protocol_ = apache :: thrift :: protocol :: TBinaryProtocolT, Super_ = apache :: thrift :: protocol :: TProtocolDefaults] â Something_server.skeleton. cpp: 42: created here /usr/local/include/thrift/protocol/TBinaryProtocol.tcc:154: error: âhtonlâ was not declared in this area /usr/local/include/thrift/protocol/TBinaryProtocol.tcc: In function- âuint32_t apache member :: thrift :: protocol :: TBinaryProtocolT :: readI16 (int16_t &) [with Transport_ = apache :: thrift :: transport :: TTransport] A:

+4
source share
3 answers

it looks like you have a problem with the lack of htons (), htonl () functions, have you included the correct header?

#include <arpa/inet.h>

+2
source

On my system (Ubuntu 10.10) htons () and htonl () are declared in netinet / in.h.

I had the same error, and I fixed it by adding -DHAVE_NETINET_IN_H to the g ++ command-line options when creating my Thrift server.

This will cause the preprocessor to include netinet / in.h in thrift / protocol / TPrototol.h, so hton * declarations will be visible to the compiler.

TProtocol.h has the following lines that cause a compiler error when HAVE_NETINET_IN_H is not defined.

 #ifdef HAVE_NETINET_IN_H #include <netinet/in.h> #endif 

This might be a bug in the Thrift configure script that somehow skips the definition.

+5
source

From Gmane you need some #defines. Add -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H to your Makefile.

Eg. In makefile

 BOOST_DIR = /usr/include/boost THRIFT_DIR = /usr/local/include/thrift LIB_DIR = /usr/local/lib BOOST_LIB_DIR = /usr/lib64/boost THRIFT_LIB_DIR = /home/timothy.ohare/bin/lib g++ -DHAVE_INTTYPES_H -DHAVE_NETINET_IN_H -o CppServer -I${THRIFT_DIR} -I${BOOST_DIR} -I../gen-cpp -L${LIB_DIR} -L${BOOST_LIB_DIR} -L${THRIFT_LIB_DIR} -lthrift CppServer.cpp ${GEN_SRC} 
+1
source

Source: https://habr.com/ru/post/1384933/


All Articles