-2

So, the real deal is that I have researched a lot, inside and outside this website, and there was no such question or solution that could help me.

I'm learning C coding. This is not a big deal since I know Python and C#(Unity) quite well. The thing is that I'm trying to do applications I did before on Python, but I'm facing a problem: I'm compiling my program on a Debian 8 Virtual Machine (Oracle's Virtual Box), as follow: gcc -lm -m64 -o file.exe file.c. What happens is that when I go back to my Windows 10 machine (not virtual) it returns me that the program I'm trying to run is an unsupported 16-bit version of the program, and it's unable to run it. I really researched a lot, and could find some things, witch I did... But nothing changes... So, I think that there is an error while contacting the GCC program or on my script, bhaskara.c(yes, it's a bhaskara formula calculator):

#include <stdio.h>
#include <math.h>

float main(){
    double a, b, c, x1, x2;
    double delta;
    double d, e;
    printf("NOTE: If the numbers are integers, use .0 at the end(eg. 1 = 1.0)\n");

    printf("A = ");
    scanf("%f", &a);
    printf("B = ");
    scanf("%f", &b);
    printf("C = ");
    scanf("%f", &c);

    d = b*b;
    e = (d + 4*a*c);
    delta = sqrt(e);
    printf("Delta = %f\n", delta);

    x1 = (-b + delta)/2;
    printf("X1 = %f\n", x1);
    x2 = (-b - delta)/2;
    printf("X2 = %f\n", x2);
}

the code is ugly, actually, it's just a test...

Things I tried: -reinstalling GCC -running different options( -m32 and -m64) -compiling whith *.exe and without it to add just before use it (don't know if it makes any sense) -turning floats into doubles (code; till what I know, doubles use more bytes)

My question: What can I do to fix it? Are there mistakes on my script, that make it unable to be 64-bit? Am I using an wrong version of GCC? (4.9.2; that's all I know about it...) Are there any other options that I can use to choose the processor type? And make it available for every kind of processor? Thanks in advance, I would really appreciate if someone could answer me what is the problem, I'm really new to compiling... If my question is hard understanding, leave coments below, so I can edit it.

1 Answers1

5

There is absolutely no reason to expect a Debian installation of GCC to, by default, build Windows executables. If you run file on the output, you'll probably see something like this:

ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux)

You need an executable like this:

PE32+ executable (GUI) x86-64, for MS Windows

These are two completely different file formats. Windows will not run Linux executables (except using some kind of emulator) and Linux will not run Windows executables (except using some kind of emulator). You can use a cross-compiler to build a Linux application on Windows or a Windows application on Linux.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278