为什么我的Thrift(c_glib)示例无法使用“错误:无效转换”进行编译?

时间:2015-09-18 11:22:26

标签: c gcc makefile thrift glib

我正在尝试在官方的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框上

我的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()
}

这就是thrift-server.c:

http://pastebin.com/Q4SGAdMu

1 个答案:

答案 0 :(得分:1)

尝试使用gcc编译代码,而不是g++(更改makefile的最后一行)。 C ++,但不是C,需要void *的显式转换。

如果您出于某种原因必须使用g++,请尝试在每次调用g_object_new时添加显式强制转换,例如:

handler = (TutorialCalculatorHandler *)
            g_object_new (TYPE_TUTORIAL_CALCULATOR_HANDLER,
                          NULL);