2013-09-26 43 views
-2

我認爲這是一個非常簡單的問題,但我對命令行的使用經驗不多。我有一個我想要運行的舊C程序。它顯示了以下文字:如何用gcc參數運行(並編譯)一個C文件?

/*  This is a stand-alone program intended to generate ... It is called*/ 
/*  as follows:               */ 
/*                   */ 
/*   tw_r2fft N > outputfile.c          */ 
/*  This program will generate the ... array 'w'      */ 
/*  and output the result to the display. Redirect the     */ 
/*  output to a file as shown above.         */ 

我想(在CMD):

gcc tw_r2fft.c 1024 > outputfile.c 

gcc的錯誤信息是:

gcc: 1024: No such file or directory 

我嘗試了一些變化,但沒有成功。

回答

6

我相信文件意味着你應該先編譯和構建程序,之後調用帶有參數的可執行文件。所以你的情況,你需要做這樣的事情:

gcc tw_r2fft.c -o tw_r2fft 
./tw_r2fft 1024 > outputfile.c 
1

您需要在運行之前

gcc tw_r2fft.c -o tw_r2fft 
./tw_r2fft 1024 > outputfile.c 
1

這番話是如何使用編譯程序的解釋來編譯程序。你需要先建立它。

最簡單的:

make tw_r2fft 
./tw_r2fft 1024 > outputfile.c 

下一頁最簡單的:

gcc -o tw_r2fft tw_r2fft.c 
./tw_r2fft 1024 > outputfile.c 
2

嘗試此編譯C程序可執行的二進制:

gcc -o tw_r2fft tw_r2fft.c 

然後用適當的命令來啓動二進制在線參數:

./tw_r2fft 1024 >outputfile.c 

然後你就可以編譯和運行輸出文件以及::)

gcc -o test outputfile.c 
./test 
1

這條線將編譯程序

gcc tw_r2fft.c -o tw_r2fft 

GCC是編譯器和tw_r2fft.c是你的文件名。 -o是更改輸出文件名的一種方法。您可以在不使用-o的情況下編譯程序,但默認情況下編譯器會將輸出文件保存爲./a.out

該行執行輸出文件並傳遞命令行參數,即1024和整個程序的輸出被保存到輸出文件。ç

./tw_r2fft 1024 > outputfile.c 

仍然需要幫助

http://www.cyberciti.biz/faq/compiling-c-program-and-creating-executable-file/

相關問題