Search code examples
cgccmakefilethriftglib

Why does my Thrift (c_glib) example fail to compile with "error: invalid conversion"?


I'm trying out the thrift c_glib example (minimal version just with ping) that is available in the official thrift website, but whenever i compile the code (gcc or make) it fails with following reason:

      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

Any pointers will be really helpful. My GCC version is 4.8.2 and I'm on a ubuntu 14.10 box

And my makefile looks like this:

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

This is how my .thrift file looks like:

namespace cpp tutorial
service Calculator {
  void ping()
}

And this is the thrift-server.c:

http://pastebin.com/Q4SGAdMu


Solution

  • Try compiling your code with gcc, not g++ (change the last line of your makefile). C++, but not C, requires explicit conversions from void *.

    If you must use g++ for some reason, try instead adding an explicit cast to each call to g_object_new, e.g.:

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