c++可执行文件不能在windows7-64位不兼容的环境下运行



我写了一个简单的c++程序来计算二次方程。我用g++在ubuntu-linux上编译了它。

顺便说一下,这是代码:

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    double a,b,c;
    double x,x2;
    cout<<"Give a: ";
    cin>>a;
    cout<<"Give b: ";
    cin>>b;
    cout <<"Give c: ";
    cin>>c;
    if (a==0)
    {
        if (b==0)
        {
            if (c==0)
            {
            cout<<"Solution indeterminable";
            return 0;
            }
            else 
            {
            cout<<"No solution";
            return 0;
            }   
        }
        else
        {
        x=-c/b;
        cout<<"The only root is x: "<<x;
        return 0;
        }
    }
    else
    {
    double b_sqr=b*b;
    if (b_sqr>4*b*c)
        {
        cout<<"Complex roots: ";
        return 0;
        }
    else if (b_sqr==4*b*c)
        {
        x=-b/(2*a);
        cout<<"The only solution is x: "<<x;
        return 0;
        }
    else
        {
            x=-b+(sqrt((b*b)-(4*a*c)))/(2*2);
            x2=-b-(sqrt((b*b)-(4*a*c)))/(2*2);
            cout<<"The first root is x1: "<<x;
            cout<<"The first root is x2: "<<x2;
            return 0;
        }
    }
}

现在,当我试图在我的x64 Windows 7上运行这个时,这就是我得到的:

不支持的16位应用程序:

由于与64位版本的windows不兼容,程序或功能equation.exe无法启动或运行。请联系软件供应商,询问是否有64位Windows兼容版本

好吧,我是作者,我写了simpe c++来编码它。这个兼容性问题怎么了?

我如何在Windows7x64中运行它?谢谢

Windows无法运行针对其他操作系统的可执行文件。您需要使用针对Windows的编译器重新编译。例如,mingw可能是Windows中使用最广泛的GCC端口。

当我编译扩展名为.h的文件时,MinGW也遇到了同样的问题;如果在编译前将源文件的扩展名更改为.cpp,则可执行文件与我的64位windows7兼容。原因是什么?不知道。我是个新手。

最新更新