2014-04-12 83 views
0

我寫了一個簡單的C++程序來計算二次方程。我用g ++在ubuntu linux上編譯它。c + +可執行文件不能在Windows 7中運行 - 64位不兼容

這裏順便代碼:

#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; 
     } 
    } 
} 

現在,當我試圖在我的64位的Windows 7上運行這個,這是我得到了什麼:

不支持16位應用程序:

由於與64位版本的Windows不兼容,程序或功能方程式無法啓動或運行。請聯繫軟件供應商詢問是否有64位Windows兼容版本

嗯,我是作者,我寫了simpe C++來編寫它。這與兼容性有什麼關係?

我該如何設法在Windows 7 x64中運行它? 謝謝!

+2

您必須爲每個正在單獨運行的環境編譯它。 – chris

+0

克里斯說什麼,「16位」是紅鯡魚。 Windows無法分辨*它是什麼,所以稱它爲16位。 –

回答

2

Windows無法運行以其他操作系統爲目標的可執行文件。您需要使用面向Windows的編譯器重新編譯。例如mingw可能是Windows中使用最廣泛的GCC端口。

0

我用MinGW編譯擴展名爲.h的文件時遇到同樣的問題;如果我在編譯之前將源文件的擴展名更改爲.cpp,則可執行文件與我的64位Windows 7兼容。原因是什麼?不知道。我是一個新手。

相關問題