Why does my Thrift (c_glib) example fail to compile with "error: invalid conversion"?
Why does my Thrift (c_glib) example fail to compile with "error: invalid conversion"?
我正在试用官方网站上提供的 thrift c_glib example(只有 ping 的最小版本),但是每当我编译代码(gcc 或 make)时,它都会失败,原因如下:
thrift-server.c: In function ‘int main()’:
thrift-server.c:186:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘TutorialCalculatorHandler* {aka _TutorialCalculatorHandler*}’ [-fpermissive]
NULL);
^
thrift-server.c:194:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘CalculatorProcessor* {aka _CalculatorProcessor*}’ [-fpermissive]
NULL);
^
thrift-server.c:201:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘ThriftServerTransport* {aka _ThriftServerTransport*}’ [-fpermissive]
NULL);
^
thrift-server.c:208:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘ThriftTransportFactory* {aka _ThriftTransportFactory*}’ [-fpermissive]
NULL);
^
thrift-server.c:214:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘ThriftProtocolFactory* {aka _ThriftProtocolFactory*}’ [-fpermissive]
NULL);
^
thrift-server.c:225:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘ThriftServer* {aka _ThriftServer*}’ [-fpermissive]
NULL);
^
thrift-server.c:176:7: warning: unused variable ‘exit_status’ [-Wunused-variable]
int exit_status = 0;
^
thrift-server.c: At global scope:
thrift-server.c:154:1: warning: ‘void sigint_handler(int)’ defined but not used [-Wunused-function]
sigint_handler (int signal_number)
^
make: *** [server] Error 1
任何指点都会很有帮助。我的 GCC 版本是 4.8.2,我在 ubuntu 14.10 box
我的 makefile 如下所示:
default: server
server: thrift-server.c
gcc -g -Wall -Wextra -pedantic -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -g -O2 -o thrift-server.o -c thrift-server.c /home/akhld/mobi/localcluster/codes/private/simdprototype/thrift-0.9.2/tutorial/c_glib/.libs/libtutorialgencglib.a -lgobject-2.0 -lglib-2.0 /home/akhld/mobi/localcluster/codes/private/simdprototype/thrift-0.9.2/lib/c_glib/.libs/libthrift_c_glib.so /home/akhld/mobi/localcluster/codes/private/simdprototype/thrift-0.9.2/lib/c_glib/.libs/libthrift_c_glib.so -lssl -lcrypto -lrt -lpthread -Wl,-rpath -Wl,/home/akhld/mobi/localcluster/codes/private/simdprototype/thrift-0.9.2/lib/c_glib/.libs
这是我的 .thrift 文件的样子:
namespace cpp tutorial
service Calculator {
void ping()
}
这是节俭-server.c:
尝试使用 gcc
而不是 g++
编译您的代码(更改您的 makefile 的最后一行)。 C++,但不是 C,需要从 void *
.
显式转换
如果您出于某种原因必须使用 g++
,请尝试在每次调用 g_object_new
时添加显式转换,例如:
handler = (TutorialCalculatorHandler *)
g_object_new (TYPE_TUTORIAL_CALCULATOR_HANDLER,
NULL);
我正在试用官方网站上提供的 thrift c_glib example(只有 ping 的最小版本),但是每当我编译代码(gcc 或 make)时,它都会失败,原因如下:
thrift-server.c: In function ‘int main()’:
thrift-server.c:186:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘TutorialCalculatorHandler* {aka _TutorialCalculatorHandler*}’ [-fpermissive]
NULL);
^
thrift-server.c:194:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘CalculatorProcessor* {aka _CalculatorProcessor*}’ [-fpermissive]
NULL);
^
thrift-server.c:201:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘ThriftServerTransport* {aka _ThriftServerTransport*}’ [-fpermissive]
NULL);
^
thrift-server.c:208:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘ThriftTransportFactory* {aka _ThriftTransportFactory*}’ [-fpermissive]
NULL);
^
thrift-server.c:214:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘ThriftProtocolFactory* {aka _ThriftProtocolFactory*}’ [-fpermissive]
NULL);
^
thrift-server.c:225:23: error: invalid conversion from ‘gpointer {aka void*}’ to ‘ThriftServer* {aka _ThriftServer*}’ [-fpermissive]
NULL);
^
thrift-server.c:176:7: warning: unused variable ‘exit_status’ [-Wunused-variable]
int exit_status = 0;
^
thrift-server.c: At global scope:
thrift-server.c:154:1: warning: ‘void sigint_handler(int)’ defined but not used [-Wunused-function]
sigint_handler (int signal_number)
^
make: *** [server] Error 1
任何指点都会很有帮助。我的 GCC 版本是 4.8.2,我在 ubuntu 14.10 box
我的 makefile 如下所示:
default: server
server: thrift-server.c
gcc -g -Wall -Wextra -pedantic -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -g -O2 -o thrift-server.o -c thrift-server.c /home/akhld/mobi/localcluster/codes/private/simdprototype/thrift-0.9.2/tutorial/c_glib/.libs/libtutorialgencglib.a -lgobject-2.0 -lglib-2.0 /home/akhld/mobi/localcluster/codes/private/simdprototype/thrift-0.9.2/lib/c_glib/.libs/libthrift_c_glib.so /home/akhld/mobi/localcluster/codes/private/simdprototype/thrift-0.9.2/lib/c_glib/.libs/libthrift_c_glib.so -lssl -lcrypto -lrt -lpthread -Wl,-rpath -Wl,/home/akhld/mobi/localcluster/codes/private/simdprototype/thrift-0.9.2/lib/c_glib/.libs
这是我的 .thrift 文件的样子:
namespace cpp tutorial
service Calculator {
void ping()
}
这是节俭-server.c:
尝试使用 gcc
而不是 g++
编译您的代码(更改您的 makefile 的最后一行)。 C++,但不是 C,需要从 void *
.
如果您出于某种原因必须使用 g++
,请尝试在每次调用 g_object_new
时添加显式转换,例如:
handler = (TutorialCalculatorHandler *)
g_object_new (TYPE_TUTORIAL_CALCULATOR_HANDLER,
NULL);