mex doesn't recognize inline - c

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

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++.

Building thrift c glib

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

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
}

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.

Still the "error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token"

This is a small pure C program illustrative of the problem. The program doesn't do anything; it's a stripped-down version of a larger program that exhibits the same problem.
Here is the scenario:
Mac OS X Lion;
gcc version i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00);
Sample code:
#include <stdlib.h>
#include <stdio.h>
char huge *pbA;
char huge *pbB;
int main(int argc,char *argv[])
{
pbA = (char huge *)farmalloc(2);
pbB = pbA;
*(pbB++) = 'A';
return( 0 );
}
Compile command:
gcc -c -Wall -O -g -pipe -D_SDL myTest.c
Errors messages:
myTest.c:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
myTest.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
myTest.c: In function ‘main’:
myTest.c:10: error: ‘pbA’ undeclared (first use in this function)
myTest.c:10: error: (Each undeclared identifier is reported only once
myTest.c:10: error: for each function it appears in.)
myTest.c:10: error: expected ‘)’ before ‘huge’
myTest.c:10: warning: implicit declaration of function ‘farmalloc’
myTest.c:11: error: ‘pbB’ undeclared (first use in this function)
So, what am I missing?
I'm not sure what/where huge is, but the compiler can't find it in what you've given it (i.e. you're missing a header probably). As for farmalloc, that looks to be in <alloc.h>. Now about using these, there is an answer on another site for huge:
Keywords like near/far/huge were once used as memory models in the old MSDOS
days when computers had a max of 640K memory.
Any machine built in the last 15 years does not have that restriction so
unless you have a real issue where you have to use really obsolete hardware,
I would not spend time with segmented memory model syntax.
huge, and probably farmalloc as well, seem to be deprecated by today's standards (just like far vs near pointers). Using just char * and malloc should be all you need; no strange, old headers.

Resources