c - 为什么我的 Thrift (c_glib) 示例无法使用 "error: invalid conversion"进行编译?

标签 c gcc makefile thrift glib

我正在尝试节俭c_glib example (只需 ping 的最小版本)可在官方 thrift 网站上找到,但每当我编译代码(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

最佳答案

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

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

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

关于c - 为什么我的 Thrift (c_glib) 示例无法使用 "error: invalid conversion"进行编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32650797/

相关文章:

我们可以在 c 中使用 "#elif !"吗?

c - make 找不到源文件,直接运行 cc 就可以了

python - 将值从 python 脚本返回到 makefile 变量

objective-c - 如何搜索有关数值宏的文档?

python - cryptopp 错误 : expected '=' , ',' 、 ';' 、 'asm' 或 '__attribute__' 在 '{' token 之前

c - 将正 double 型强制转换为 unsigned int 实现是已定义的还是可移植的?

gcc - 有没有办法在gcc中使用内联asm使用在编译时求值的表达式?

c++ - 带有外部库的 CMake 'no rule to make target'

c - 在 C 代码中使用库

C:在数组中搜索非数字字符