Estoy teniendo un problema al intentar compilar el archivo hello.c:
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("Hello from LinuxHint \n");
return 0;
}
Después de esto tipeo gcc hello.c y muestra:
(base) ale@ale-HP-250-G7-Notebook-PC:~/Programacion/test$ gcc hello.c
In file included from /usr/local/include/corecrt.h:10:0,
from /usr/local/include/crtdefs.h:10,
from /usr/local/include/stdio.h:9,
from hello.c:1:
/usr/local/include/_mingw.h:273:2: error: #error Only Win32 target is supported!
#error Only Win32 target is supported!
^~~~~
In file included from hello.c:1:0:
/usr/local/include/stdio.h:80:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__acrt_iob_func’
_CRTIMP FILE *__cdecl __acrt_iob_func(unsigned index);
^~~~~~~~~~~~~~~
/usr/local/include/stdio.h:167:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_sscanf’
int __cdecl __mingw_sscanf(const char * __restrict__ _Src,const char * __restrict__ _Format,...);
^~~~~~~~~~~~~~
/usr/local/include/stdio.h:170:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_vsscanf’
int __cdecl __mingw_vsscanf (const char * __restrict__ _Str,const char * __restrict__ Format,va_list argp);
^~~~~~~~~~~~~~~
/usr/local/include/stdio.h:173:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_scanf’
int __cdecl __mingw_scanf(const char * __restrict__ _Format,...);
^~~~~~~~~~~~~
/usr/local/include/stdio.h:176:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_vscanf’
int __cdecl __mingw_vscanf(const char * __restrict__ Format, va_list argp);
^~~~~~~~~~~~~~
/usr/local/include/stdio.h:179:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_fscanf’
int __cdecl __mingw_fscanf(FILE * __restrict__ _File,const char * __restrict__ _Format,...);
^~~~~~~~~~~~~~
/usr/local/include/stdio.h:182:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_vfscanf’
int __cdecl __mingw_vfscanf (FILE * __restrict__ fp, const char * __restrict__ Format,va_list argp);
^~~~~~~~~~~~~~~
/usr/local/include/stdio.h:186:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_vsnprintf’
int __cdecl __mingw_vsnprintf(char * __restrict__ _DstBuf,size_t _MaxCount,const char * __restrict__ _Format,
^~~~~~~~~~~~~~~~~
/usr/local/include/stdio.h:190:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_snprintf’
int __cdecl __mingw_snprintf(char * __restrict__ s, size_t n, const char * __restrict__ format, ...);
^~~~~~~~~~~~~~~~
/usr/local/include/stdio.h:193:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_printf’
int __cdecl __mingw_printf(const char * __restrict__ , ... ) __MINGW_NOTHROW;
^~~~~~~~~~~~~~
/usr/local/include/stdio.h:196:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_vprintf’
int __cdecl __mingw_vprintf (const char * __restrict__ , va_list) __MINGW_NOTHROW;
^~~~~~~~~~~~~~~
/usr/local/include/stdio.h:199:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_fprintf’
int __cdecl __mingw_fprintf (FILE * __restrict__ , const char * __restrict__ , ...) __MINGW_NOTHROW;
^~~~~~~~~~~~~~~
/usr/local/include/stdio.h:202:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_vfprintf’
int __cdecl __mingw_vfprintf (FILE * __restrict__ , const char * __restrict__ , va_list) __MINGW_NOTHROW;
^~~~~~~~~~~~~~~~
/usr/local/include/stdio.h:205:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_sprintf’
int __cdecl __mingw_sprintf (char * __restrict__ , const char * __restrict__ , ...) __MINGW_NOTHROW;
^~~~~~~~~~~~~~~
/usr/local/include/stdio.h:208:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_vsprintf’
int __cdecl __mingw_vsprintf (char * __restrict__ , const char * __restrict__ , va_list) __MINGW_NOTHROW;
^~~~~~~~~~~~~~~~
/usr/local/include/stdio.h:211:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_asprintf’
int __cdecl __mingw_asprintf(char ** __restrict__ , const char * __restrict__ , ...) __MINGW_NOTHROW;
^~~~~~~~~~~~~~~~
/usr/local/include/stdio.h:214:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__mingw_vasprintf’
int __cdecl __mingw_vasprintf(char ** __restrict__ , const char * __restrict__ , va_list) __MINGW_NOTHROW;
^~~~~~~~~~~~~~~~~
In file included from hello.c:1:0:
/usr/local/include/stdio.h:555:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fprintf’
int __cdecl fprintf(FILE * __restrict__ _File,const char * __restrict__ _Format,...);
^~~~~~~
/usr/local/include/stdio.h:557:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘printf’
int __cdecl printf(const char * __restrict__ _Format,...);
^~~~~~
/usr/local/include/stdio.h:559:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘sprintf’
int __cdecl sprintf(char * __restrict__ _Dest,const char * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
^~~~~~~
/usr/local/include/stdio.h:562:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘vfprintf’
int __cdecl vfprintf(FILE * __restrict__ _File,const char * __restrict__ _Format,va_list _ArgList);
^~~~~~~~
/usr/local/include/stdio.h:564:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘vprintf’
int __cdecl vprintf(const char * __restrict__ _Format,va_list _ArgList);
^~~~~~~
/usr/local/include/stdio.h:566:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘vsprintf’
int __cdecl vsprintf(char * __restrict__ _Dest,const char * __restrict__ _Format,va_list _Args) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
^~~~~~~~
/usr/local/include/stdio.h:569:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fscanf’
int __cdecl fscanf(FILE * __restrict__ _File,const char * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
^~~~~~
/usr/local/include/stdio.h:571:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘scanf’
int __cdecl scanf(const char * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
^~~~~
/usr/local/include/stdio.h:573:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘sscanf’
int __cdecl sscanf(const char * __restrict__ _Src,const char * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
^~~~~~
/usr/local/include/stdio.h:585:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__ms_vscanf’
int __cdecl __ms_vscanf(const char * __restrict__ Format, va_list argp);
^~~~~~~~~~~
/usr/local/include/stdio.h:587:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__ms_vfscanf’
int __cdecl __ms_vfscanf (FILE * __restrict__ fp, const char * __restrict__ Format,va_list argp);
^~~~~~~~~~~~
/usr/local/include/stdio.h:589:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__ms_vsscanf’
int __cdecl __ms_vsscanf (const char * __restrict__ _Str,const char * __restrict__ Format,va_list argp);
^~~~~~~~~~~~
/usr/local/include/stdio.h:593:3: error: expected ‘,’ or ‘;’ before ‘int’
int vfscanf (FILE *__stream, const char *__format, __builtin_va_list __local_argv)
^~~
/usr/local/include/stdio.h:600:3: error: expected ‘,’ or ‘;’ before ‘int’
int vsscanf (const char * __restrict__ __source, const char * __restrict__ __format, __builtin_va_list __local_argv)
^~~
/usr/local/include/stdio.h:606:3: error: expected ‘,’ or ‘;’ before ‘int’
int vscanf(const char *__format, __builtin_va_list __local_argv)
^~~
/usr/local/include/stdio.h:619:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_filbuf’
_CRTIMP int __cdecl _filbuf(FILE *_File);
^~~~~~~
/usr/local/include/stdio.h:620:23: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_flsbuf’
_CRTIMP int __cdecl _flsbuf(int _Ch,FILE *_File);
^~~~~~~
/usr/local/include/stdio.h:624:25: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_fsopen’
_CRTIMP FILE *__cdecl _fsopen(const char *_Filename,const char *_Mode,int _ShFlag);
^~~~~~~
/usr/local/include/stdio.h:626:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘clearerr’
void __cdecl clearerr(FILE *_File);
And it continues....
Cosas que intenté:
- Reinstalar el build-essentials package
- Usar algunos flags para el preprocesador como -D__CYGWIN__ -D_CRTIMP --std=gnu99 (con esto pude pasar algunos errores pero falla luego)
- Probé correr el ./configure script pero falla, me dice que debo tener el install sh en la misma carpeta y no se donde está
- Probé compilar con x86_64-w64-mingw32-gcc hello.c, la compilación es exitosa pero cuando ejecuto ./a.exe dice: cannot execute binary file: Exec format error. Según leí de esta forma se cross-compila para Windows 64bit. Debería usar solo gcc para que compile para Linux 64 bit?
- Probé usar g++ con un hello.cpp y tengo también el mismo error del Only Win32... se ve que el compilador de alguna manera espera estar en una PC de 32 bits, pero la mía es de 64 bits...
Acá está el output de mi gcc -v:
(base) ale@ale-HP-250-G7-Notebook-PC:~/Programacion/test$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
(base) ale@ale-HP-250-G7-Notebook-PC:~/Programacion/test$
Que otra cosa puedo hacer? Estoy perdido. Capaz reinstalar Linux después de formatear el disco? Instalé Linux para aprender y poder programar en C.
Gracias,