VC6.0命令列編譯

來源:互聯網
上載者:User

VC6.0命令列編譯及使用makefile編譯的方法

VC6是挺經典的一個IDE,但有時編譯比較慢。作為一個典型的程式員,我總想讓電腦多做點事,自己少點事。編譯軟體也一樣,又是能夠執行後不管了,讓程式自己慢慢編譯,人可以做其他事情,或者直接寫成批處理,自動的一個個慢慢執行編譯就好了。所以一直想探索一下vc6環境怎麼使用命令列編譯,以及vc6怎麼使用makefile編譯。

今天終於找到辦法!雖然還停留在初淺的層面,但還是可以做到命令列自動編譯了。所以寫下來既是分享,也供自己以後查閱。

一、VC6命令列編譯

VC6對應的可執行檔是msdev,在命令列視窗(以下簡稱cmd)中輸入msdev /? 斷行符號就能看到msdev的命令列參數協助了(如果提示未知命令,那麼請使用vc6安裝目錄下的VCVARS32.BAT設定環境)。協助資訊如下:

F:\VC_Code\maintest>msdev/?

Usage:

  MSDEV [myprj.dsp|mywksp.dsw]  - load project/workspace

        [<filename>]            - load source file

        /?                      - display usageinformation

        /EX <macroname>         - execute a VBScript macro

        /OUT <filename>         - redirect command line output to afile

        /USEENV                 - ignoretools.options.directories settings

        /MAKE [<target>] [...]  - build specified target(s)

              [<project> -<platform> <configname>]

              [[<project>|ALL] -[DEBUG|RELEASE|ALL]]

              /CLEAN            - delete intermediate files butdon't build

              /REBUILD          - clean and build

              /NORECURSE        - don't build dependent projects

 

下面逐個參數論述:

[myprj.dsp|mywksp.dsw]  - load project/workspace

[<filename>]            - load source file

/?                      - display usage information

/EX<macroname>         - execute aVBScript macro

/USEENV                 - ignoretools.options.directories settings

這幾個選項跟本文想論述的內容關係不大,也比較好懂,有興趣的人自己動手試一下就知道了。

/OUT<filename>         - redirectcommand line output to a file 把輸入資訊重新導向到檔案中,可以跟編譯指令結合,儲存編譯過程的輸出資訊,有利於確認編譯成功與否,特別是使用批處理批量編譯時間。

/MAKE 就是主角了,就是編譯指令了。下面以幾個樣本來說明吧:

(1)編譯工作區檔案(dsw)的項目

msdev maintest.dsw/make "all - win32 debug" /out f:\result.txt

maintest.dsw 工作區檔案

/make 編譯指令

all 編譯所有項目(project),如果工作區有多重專案,也可以指定只編譯特定項目,可以使用記事本開啟dsw檔案,可以看到裡麵包含的各個專案檔。

win32 平台(platform),vc6運行基本也就是win32平台了,所以一般該參數可以省略。

debug 編譯設定項(configname),可以在DEBUG|RELEASE|ALL選擇

/out f:\result.txt 重新導向輸出,把編譯過程的資訊輸出到f:\result.txt中。

所以上面的命令列的意思就是:把maintest.dsw工作區裡的所有項目編譯debug版的產品,並把編譯過程的資訊輸出到f:\result.txt中。

據此可以容易理解下面幾個命令列的意思吧:

msdev maintest.dsw /make "all - win32release"  –所有項目編譯release版

msdev maintest.dsw /make "all -all"  --所有項目編譯debug和release版

msdev maintest.dsw /make "maintest -release" –編譯工作區中的maintest項目的release版

(2)編譯專案檔(dsp)的項目

msdev maintest.dsp/make "all - win32 debug" /out f:\result.txt

maintest.dsp 項目設定檔

其他參數都跟編譯工作區檔案(dsw)的項目一樣,注意其他的all,一直保持all就行了,因為項目設定檔裡面也就只包含一個項目了。

/CLEAN            - delete intermediate files butdon't build

/REBUILD          - clean and build

跟圖形化VC6 IDE中的BUILD->CLEAN和BUILD->REBUILD ALL意義是一樣的,這裡就不贅述了。

二、VC6使用makefile編譯

VC6 IDE帶的makefile編譯器是nmake,也可以在cmd中輸入nmake /?擷取詳細的協助資訊,因為我自己沒有一一使用過,所以也就不一一論述了。下面只提供一個使用的方法:

(1)在VC6圖形化介面上開啟一個項目,然後執行Project->Export Makefile,會在項目的目錄下產生mak和dep兩個檔案,這就是項目配置的makefile了。

(2)然後使用如下命令列編譯了:

NMAKE /f "maintest.mak"CFG="maintest - Win32 Debug" /y /d

NMAKE /f "maintest.mak"CFG="maintest - Win32 Release" /y /d

注意這裡的CFG="maintest- Win32 Debug"區分大小寫,而msdev的/make "all - win32 release"是不區分大小寫。

如果你有興趣繼續探索,可以使用記事本開啟dsp和mak檔案看一下。

(轉自http://hi.baidu.com/chenwenjun721/item/1a19798d0886a5814514cf60)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.