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++.
Related
i am trying to compile c file in linux OS but i'm getting so many errors.
I searched it on internet and found solution that is to install mingw-w64. I installed but getting the same error.
here is my first.c file :
#include<stdio.h>
int main()
{
printf("Hello world");
return 0;
}
here what i got after compiling :
┌──(root💀kali)-[/home/dj/Desktop/c/graphics]
└─# gcc first.c -o output 1 ⚙
In file included from /usr/local/include/corecrt.h:10,
from /usr/local/include/corecrt_stdio_config.h:10,
from /usr/local/include/stdio.h:9,
from first.c:1:
/usr/local/include/_mingw.h:272:2: error: #error Only Win32 target is supported!
272 | #error Only Win32 target is supported!
| ^~~~~
In file included from /usr/local/include/corecrt.h:10,
from /usr/local/include/corecrt_stdio_config.h:10,
from /usr/local/include/stdio.h:9,
from first.c:1:
/usr/local/include/_mingw.h:580:14: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__debugbreak’
580 | void __cdecl __debugbreak(void);
| ^~~~~~~~~~~~
/usr/local/include/_mingw.h:581:36: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__debugbreak’
581 | __MINGW_INTRIN_INLINE void __cdecl __debugbreak(void)
| ^~~~~~~~~~~~
In file included from first.c:1:
/usr/local/include/stdio.h:93:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__acrt_iob_func’
93 | _CRTIMP FILE *__cdecl __acrt_iob_func(unsigned index);
| ^~~~~~~~~~~~~~~
/usr/local/include/stdio.h:158:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_sscanf’
158 | int __cdecl __mingw_sscanf(const char * __restrict__ _Src,const char * __restrict__ _Format,...);
| ^~~~~~~~~~~~~~
/usr/local/include/stdio.h:161:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_vsscanf’
161 | int __cdecl __mingw_vsscanf (const char * __restrict__ _Str,const char * __restrict__ Format,va_list argp);
...
/usr/local/include/sec_api/stdio_s.h:857:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_vscwprintf_l’
857 | _CRTIMP int __cdecl _vscwprintf_l(const wchar_t *_Format,_locale_t _Locale,va_list _ArgList);
| ^~~~~~~~~~~~~
/usr/local/include/sec_api/stdio_s.h:858:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_fwscanf_l’
858 | _CRTIMP int __cdecl _fwscanf_l(FILE *_File,const wchar_t *_Format,_locale_t _Locale,...);
| ^~~~~~~~~~
/usr/local/include/sec_api/stdio_s.h:859:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_swscanf_l’
859 | _CRTIMP int __cdecl _swscanf_l(const wchar_t *_Src,const wchar_t *_Format,_locale_t _Locale,...);
| ^~~~~~~~~~
/usr/local/include/sec_api/stdio_s.h:860:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_snwscanf_l’
860 | _CRTIMP int __cdecl _snwscanf_l(const wchar_t *_Src,size_t _MaxCount,const wchar_t *_Format,_locale_t _Locale,...);
| ^~~~~~~~~~~
/usr/local/include/sec_api/stdio_s.h:861:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_wscanf_l’
861 | _CRTIMP int __cdecl _wscanf_l(const wchar_t *_Format,_locale_t _Locale,...);
| ^~~~~~~~~
first.c:4:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
4 | {
| ^
first.c:7: error: expected ‘{’ at end of input
7 | }
|
please help me to solve this.
Thanks in advance
The Mingw-w64 compiler is for windows. If you're using linux, then you just need to install gcc which should be already preinstalled on your system. Just remove the mingw package and it should work then.
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
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
}
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
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.