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.
Related
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 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
}
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.
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.