2011-04-14 137 views
0

我在嘗試在linux下安裝交叉編譯器時遇到困難。 我下載了一個似乎沒問題的工具鏈,但接下來呢?我需要在控制檯中鍵入什麼命令才能使其安裝?如何安裝gcc交叉編譯器

目的是將C代碼轉換爲MIPS(小端)代碼。

其實我需要一次只有2碼,所以如果有人只能說明我在MIPS這些代碼,我會很樂意......

第一碼:

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 

#define SIZE 128 

int main() 

{ 
    char mychar , string [SIZE]; 
    int i; 
    int count =0 ; 

    printf ("Please enter your string: \n\n"); 
    fgets (string, SIZE, stdin); 

    printf ("Please enter char to find: "); 
    mychar = getchar(); 

    for (i=0 ; string[i] != '\0' ; i++) 
     if (string[i] == mychar) 
      count++; 

    printf ("The char %c appears %d times\n" ,mychar ,count); 


    return 0; 
} 

第二碼:

#include <stdio.h> 
#include <string.h> 

void SIFT(int x_arr[ ], int y_arr[]); 

int main() 
{ 
    int x[20] = {0} , y[20] = {0}; 
    int m=0,temp=0,curr=0,i=0,j=0; 

    printf("Please enter your numbers now:\n\n"); 

    /*enter numbers one by one. if x[i+1] value < x[i] value, err msg. 
     when user want to end the series he must enter '0' which means end of string (it wont  included in x[]) */ 
    while ((scanf("%d",&temp)) != 5) 
    { 
     if (temp >= curr) 
     { 
      x[i] = temp; 
      curr = temp; 
      i++; 
     } 
     else 
     { 
      printf("The numbers are not at the right order !\n\nProgram will now terminate...\n\n"); 
     } 
    } 

    SIFT(x,y); 

    for (i=0 ; y[i]=='0' ; i++) /*strlen(y) without ('0')'s includes*/ 
     m++; 

    /*Prints m , y's organs*/ 
    printf("\n\nm = %d",m); 
    printf("Y = "); 
    while (y[j]!='0') 
    { 
     printf ("%d ,",y[j]); 
     j++; 
    } 

return 0; 
} 

void SIFT(int x_arr[ ], int y_arr[]) 
{ 
    int i=0,j=0; 

    while (x_arr[i] != '0') 
    { 
     if (x_arr[i] == x_arr[i+1]) /*if current val. equals next val. -> jump dbl at x_arr*/ 
     { 
      y_arr[j] = x_arr[i]; 
      i+=2; 
      j++; 
     } 
     else 
     { 
      y_arr[j]=x_arr[i]; 
      i++; 
      j++; 
     } 
    }  

} 
+0

你不會將代碼轉換爲mips,但編譯它 - 嘗試運行'mips-gcc'之類的東西。或嘗試列出工具鏈中存檔的文件 – fazo 2011-04-14 21:32:40

+0

都嘗試過,沒有發現任何東西......也許你有一個,只能編譯2個代碼給我? – 2011-04-14 21:38:14

+0

你想做什麼? – 2011-04-14 21:43:32

回答

0

您可能需要使用crosstool-NG卜嘗試爲你的系統安裝一個工具鏈。

+0

這對我來說並不複雜......不能理解...... – 2011-04-14 21:40:50

+1

你看過[使用說明](http://ymorin.is-a-geek.org/projects/crosstool#download_and_usage) ?他們不是很複雜 – Hasturkun 2011-04-14 21:43:14

+0

它說:「現在測試:」和那些線路不安靜瞭解... – 2011-04-14 21:49:03

0

我不知道這是否會幫助你,但我已經編譯使用ECC源文件(http://ellcc.org),並得到了:

http://pastebin.com/keDPEcsc 

http://pastebin.com/zQBsMVfS 

希望有所幫助。

+0

如果這是一項家庭作業,我很抱歉。 1.我沒有使用gcc,2.我編譯爲big endian mips。 ;-) – 2011-04-14 22:12:03

+0

謝謝理查! 像魔法一樣工作:) – 2011-04-14 22:26:33