Building thrift c glib - c

I used the thrift compiler to generate C-glib files. However they never seem to compile.
My .c file:
#include "zipkin_core_types.h"
void genLogfile(Span span, char *filename) {
}
My .h file
#include "zipkin_core_types.h"
#ifndef SPANLOGGERCH
#define SPANLOGGERCH
void genLogfile(Span span, char *filename);
#endif
command line options:
gcc -g -o main -I/usr/include/glib-2.0/ -I /usr/lib/glib/include/ -I/usr/local/include/thrift/ -I/usr/local/include/thrift/c_glib -I. -L/usr/local/lib/-I/usr/lib/glib-2.0/include/ -lthrift main.c zipkin_core_types.c SpanLoggerC.c
I get 5 screens of error messages. Here's the top few lines, they mostly look like this. Any suggestions woule be appreciated:
In file included from /usr/include/glib-2.0/glib/galloca.h:30,
from /usr/include/glib-2.0/glib.h:30,
from /usr/include/glib-2.0/gobject/gtype.h:26,
from /usr/include/glib-2.0/gobject/gboxed.h:26,
from /usr/include/glib-2.0/glib-object.h:25,
from zipkin_core_types.h:11,
from SpanLoggerC.h:1,
from main.c:1:
/usr/include/glib-2.0/glib/gtypes.h:41: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘typedef’
/usr/include/glib-2.0/glib/gtypes.h:90: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
In file included from /usr/include/glib-2.0/glib.h:31,
from /usr/include/glib-2.0/gobject/gtype.h:26,
from /usr/include/glib-2.0/gobject/gboxed.h:26,
from /usr/include/glib-2.0/glib-object.h:25,
from zipkin_core_types.h:11,
from SpanLoggerC.h:1,
from main.c:1:
/usr/include/glib-2.0/glib/garray.h:32: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘G_BEGIN_DECLS’
/usr/include/glib-2.0/glib/garray.h:40: error: expected specifier-qualifier-list before ‘gchar’
/usr/include/glib-2.0/glib/garray.h:66: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/glib-2.0/glib/garray.h:69: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/glib-2.0/glib/garray.h:73: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token

Related

Error creating a class in C

I've some error on this class construction,
cwrapper.h
#include "SimpleCLM.h"
using namespace std;
using namespace cv;
class A{
public:
A();
~A();
met1();
};
void *A_init();
A_m1(void *p);
cwrapper.c
#include "cwrapper.h"
using namespace std;
using namespace cv;
void *A_init()
{
A *p = new A;
return (void *)p;
}
A_m1(void *p)
{
return p->met1();
}
A::met1()
{
return begin();
}
begin is a function in SimpleCLM.h.
Here is the errors on make,
In file included from /home/samuel/Desktop/matlab_cpp/cwrapper.h:1,
from /home/samuel/Desktop/matlab_cpp/cwrapper.c:1:
/home/samuel/Desktop/matlab_cpp/SimpleCLM.h:2: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘begin’
In file included from /home/samuel/Desktop/matlab_cpp/cwrapper.c:1:
/home/samuel/Desktop/matlab_cpp/cwrapper.h:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘namespace’
/home/samuel/Desktop/matlab_cpp/cwrapper.h:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘namespace’
/home/samuel/Desktop/matlab_cpp/cwrapper.h:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘A’
/home/samuel/Desktop/matlab_cpp/cwrapper.h:14: warning: data definition has no type or storage class
/home/samuel/Desktop/matlab_cpp/cwrapper.c:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘namespace’
/home/samuel/Desktop/matlab_cpp/cwrapper.c:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘namespace’
/home/samuel/Desktop/matlab_cpp/cwrapper.c: In function ‘A_init’:
/home/samuel/Desktop/matlab_cpp/cwrapper.c:8: error: ‘A’ undeclared (first use in this function)
/home/samuel/Desktop/matlab_cpp/cwrapper.c:8: error: (Each undeclared identifier is reported only once
/home/samuel/Desktop/matlab_cpp/cwrapper.c:8: error: for each function it appears in.)
/home/samuel/Desktop/matlab_cpp/cwrapper.c:8: error: ‘p’ undeclared (first use in this function)
/home/samuel/Desktop/matlab_cpp/cwrapper.c:8: error: ‘new’ undeclared (first use in this function)
/home/samuel/Desktop/matlab_cpp/cwrapper.c:8: error: expected ‘;’ before ‘A’
/home/samuel/Desktop/matlab_cpp/cwrapper.c: In function ‘A_m1’:
/home/samuel/Desktop/matlab_cpp/cwrapper.c:14: warning: dereferencing ‘void *’ pointer
/home/samuel/Desktop/matlab_cpp/cwrapper.c:14: error: request for member ‘met1’ in something not a structure or union
/home/samuel/Desktop/matlab_cpp/cwrapper.c: At top level:
/home/samuel/Desktop/matlab_cpp/cwrapper.c:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
make[2]: *** [CMakeFiles/cwrapper.dir/cwrapper.c.o] Error 1
make[1]: *** [CMakeFiles/cwrapper.dir/all] Error 2
make: *** [all] Error 2
It is impossible to create a class in C; you would have to tell the compiler somehow that you want to compile C++.

I am trying to run this simple program but I have this error message "expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token"

This is the full error message
hw2.c:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘<’ token
This is the line in question
int main <void>
I can post more info if anyone needs it.
I assume you're trying to create a main method?
int main(void){
// lol code
}

error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before function_name

Here is the error:
msp430-gcc -mmcu=msp430g2553 -Os -c -o gpio_test.o gpio_test.c
In file included from msp430_lib.h:9:0,
from gpio_test.c:4:
gpio_api.h:20:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘gpio_init’
gpio_api.h:27:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘gpio_ioctl_pull_en’
gpio_api.h:35:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘gpio_write’
make: *** [gpio_test.o] Error 1
Here is the header file where the error is coming from(The line numbers don't match up because I stripped all the comments out of the file to shorten it):
/* gpio_api.h - General Purpose Input/Output API
*/
#ifndef MSP_GPIO_API_H
#define MSP_GPIO_API_H
#include <msp430g2553.h>
#define INPUT 0
#define OUTPUT 1
#define DOWN 0
#define UP 1
bool gpio_init(int port, int pin, int direction);
bool gpio_ioctl_pull_en(int port, int pin, int direction);
bool gpio_write(int port, int pin, int value);
int gpio_read (int port, int pin);
#endif
It seems simple enough, yet I can't figure out what my problem is.
You have to include <stdbool.h> in your program. bool is actually a macro defined in stdbool.h header file.

mex doesn't recognize inline

I'm trying to compile a matlab wrapper for libdc1394 which is a library for firewire cameras.
I get a strange error involving some inline functions in a header file.
I'm working on ubuntu 12.04 with gcc-4.6. I've compiled other mex files with success. This wrapper was also difficult to compile in mac.
/usr/local/MATLAB/R2012b//bin/mex dc1394mex.c `pkg-config --libs --cflags libdc1394-2` -o dc1394.mexa64
Warning: You are using gcc version "4.6.3-1ubuntu5)". The version
currently supported with MEX is "4.4.6".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
In file included from /usr/include/dc1394/dc1394.h:53:0,
from dc1394mex.c:23:
/usr/include/dc1394/register.h:47:1: error: unknown type name ‘inline’
/usr/include/dc1394/register.h:47:29: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘dc1394_get_register’
/usr/include/dc1394/register.h:62:1: error: unknown type name ‘inline’
/usr/include/dc1394/register.h:62:29: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘dc1394_set_register’
/usr/include/dc1394/register.h:82:1: error: unknown type name ‘inline’
/usr/include/dc1394/register.h:82:29: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘dc1394_get_control_register’
/usr/include/dc1394/register.h:97:1: error: unknown type name ‘inline’
/usr/include/dc1394/register.h:97:29: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘dc1394_set_control_register’
/usr/include/dc1394/register.h:117:1: error: unknown type name ‘inline’
/usr/include/dc1394/register.h:118:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘dc1394_get_adv_control_register’
/usr/include/dc1394/register.h:133:1: error: unknown type name ‘inline’
/usr/include/dc1394/register.h:134:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘dc1394_set_adv_control_register’
dc1394mex.c: In function ‘command_init_camera’:
dc1394mex.c:133:12: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
dc1394mex.c:152:12: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
dc1394mex.c: In function ‘dcframe_to_mxframe’:
dc1394mex.c:571:1: error: expected expression before ‘/’ token
dc1394mex.c:572:1: error: expected expression before ‘/’ token
dc1394mex.c:573:1: error: expected expression before ‘/’ token
mex: compile of ' "dc1394mex.c"' failed.
make: *** [dc1394.mexa64] Error 1
Any ideas?
Well Simons proposal was correct. Only catch I didn't know was that you can't give cflags directly to mex. You have to alter your mexopts.sh file.
Also I had to remove -ansi flag because it contradicts with c99.
How to specify C99 via CFLAGS modification on the command line:
mex -v -largeArrayDims CFLAGS="\$CFLAGS -std=C99" dc1394mex.c

C Making volatile sig_atomic_t Global in Header File

I'm trying to make a global variable, initialized in my msh.c file as:
volatile sig_atomic_t sig_int = 0;
This alone seems to be fine. However if I go to my proto.h file(which is included in all the c files for this project), and type:
extern volatile sig_atomic_t sig_int;
It throws a bunch of errors:
gcc -c -Wall msh.c arg_parse.c builtin.c expand.c
In file included from arg_parse.c:5:
proto.h:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘sig_int’
In file included from builtin.c:13:
proto.h:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘sig_int’
In file included from expand.c:11:
proto.h:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘sig_int’
make: *** [msh.o] Error 1
How exactly do I make this variable global? Thanks.
Your proto.h file needs to include <signal.h> so that the sig_atomic_t type is defined, that's all.

Resources