使用CodeBlocks編譯64位程式(用的編譯器僅僅是windows sdk的)

來源:互聯網
上載者:User

標籤:too   blank   creat   連結   htm   and   dfa   console   技術分享   

需求:

-CodeBlocks使用nightly版本;

-Windows SDK(我使用的是6.0A,即微軟針對vista的,因為這個比較小,你也可以選擇其他版本但是要有64位編譯器。他也適用於xpsp2及以上但是要安裝.net2.0以上才能運行)對應的連結

:http://download.microsoft.com/download/4/2/6/42684501-9ec5-43dd-9dfe-c8c9dfa6a66f/6.1.6000.16384.10.WindowsSDK_Vista_Feb2007Update_rtm.DVD.Rel.iso

Step1) Make sure you have a nightly build because I don’t think that RC2 supports all the needed functionality to setup the compiler.

//廢話,上面不是說了麼。。。

Step2) Install the Windows SDK, you can deselect all the .net stuff because we won’t be needing it.

安裝WinSDK,我只選擇了Developers Tools->window Vista Headers and libraries 中的三個。其他一概不安。

Step3) Start Code::Blocks and go to ‘Settings->Compiler and Debugger settings’, then select ‘Microsoft Visual C++ 2005’ from the dropdown box and click the copy button. Now choose a name I used ‘Windows SDK x64’ but you can name it whatever you like.

//在CB裡面的編譯器設定,選擇,vc2005,我選的是vc2005/2008(新的CB版本都一樣),到頭來還是手動修改。廢話不說,把剛才說的這個設定複製出一個新的,然後隨便起個名字,我起的是wnsdkv6x64.

Step4) Now with ‘Windows SDK x64’ as the selected compiler go to the ‘Toolchain executables’ tab andEMPTY the directory text box. Then click the ‘Additional Paths’ tab inside the ‘Toolchain executables’ tab. Remove the directory that goes to your Visual C++ 2005 install dirNOT the debug one and add the following directory’s:
- C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\x64
- C:\Program Files\Microsoft SDKs\Windows\v6.0\VC\Bin\x64

//他說開始設定交叉編譯工具鏈程式(不用管,英文版本的就是‘Toolchain executables’這個標籤,說把

這個控制項清空,之後在下面的Additional Paths這個額外路徑選項卡裡面加入下面這兩個目錄,但是要把原來的那個預設的刪除掉就行了。要添加的路徑就是如下:

注意:如果你都是預設安裝就用上面的路徑就可以了。

%YourSDK%\Bin\x64     (由於我自己按照上面安裝之後在這個沒有這個目錄,我也沒設定,莫非我的版本和他的不一樣?不過我確實編譯通過了)

%YourSDK\VC\Bin\x64


Step5) Now go to the ‘Search Directories’ tab and remove all items under the ‘Compiler’, ‘Linker’ and ‘Resource compiler’ tabs. And then add the following,Compiler:
- C:\Program Files\Microsoft SDKs\Windows\v6.0\VC\INCLUDE
- C:\Program Files\Microsoft SDKs\Windows\v6.0\Include

//現在去,圖裡標註的0號位置,在1號選項卡裡面添加他說的目錄或者自訂路徑寫

%YourSDK%\VC\INCLUDE

%YourSDK%\Include

2號linker填寫下面的:

Linker:
- C:\Program Files\Microsoft SDKs\Windows\v6.0\VC\LIB\x64
- C:\Program Files\Microsoft SDKs\Windows\v6.0\Lib\x64

或者自訂目錄填寫:

%YourSDK%\Lib\x64

%YourSDK%\Lib\VC\LIB\x64

3號不用填寫,因為sdk裡面沒有。。。

Resource Compiler:
- None

Step6) Create a new project (console project) and select our new ‘Windows SDK x64’ compiler as the compiler to use. Now in the generated code add the following line:

  • cout << “sizeof(void*) = ” << sizeof(void*) << ";" << endl;
Hit the compile button and off we go. When we execute the program it appears to have a 8byte long address (64 bits).

基本完事了,這個是測試用的,他只是測試控制台程式是否能被正確編譯,反正我已經編譯出來了,看圖:

使用嚮導建立新console project,

之後就可以編譯出來了

沒有錯誤:顯示如下:

我又使用win32嚮導建立了一個標準的win32api的視窗,


絕對是64位的程式。其他的還沒試過,接下來的是使用ms2010編譯amd64的教程了,應該很容易,就是因為不想使用ms2010那麼大的體積才不用他的,誰想用就試試吧,他用的express版本來編譯amd64的,當然也要安裝winsdk,最新的vs2012據說連direct sdk都不用安裝了,沒用過不知道。

The following instructions will allow you to compile 64-bit code using Microsoft‘s VC 2010 compiler (with the Windows SDK).Requirements:
- Code::Bocks (at least as of 2012-07-23 the nightly build worked) [2]
-Microsoft Visual C++ 2010 express (or better) [3]
-Microsoft Windows SDK v7.1 (earlier versions might not work, later version will probably work but directories will change)[4]

Step 1) Install Visual Studio 2010.

Step 2) Install Windwos SDK.

Step 3) Install Code::Blocks following instructions listed in nightly build forum.

Note: Prior to setting up Code::Blocks for 64-Bit compiling, you may need to set the MSbuild environment to x64. This can be done my running the command:
"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64

Step 5) Run the new installation for the nightly build of Code::BLocks. It should auto-detect your installed compilers, including the recently installed Visual C++ 2010.
Step 6) Once Code::Blocks open the ‘Global Compiler Settings‘ (Settings->Compiler...). Select ‘Microsoft Visual C++ 2010‘.
Now under the ‘Toolchain executables‘ Tab change the Compiler‘s installation directory to:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64
Note: if you installed VC to a different directory this path will change. The important part is that you change the path to look in the ‘.\bin\amd64‘ directory.

While still in the ‘Toolchain...‘ tab, click on ‘Additional Paths‘. Add the following:
C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\x64
C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE

Next you need to add the x64 includes and lib file.
Under the ‘Search Directories‘ tab add the following to the Compiler search path:
C:\Program Files\Microsoft SDKs\Windows\v7.1\Include
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include
Note: the Windows SDK directory should be listed first

Now add the following to the Linker search path (in this order):
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64
C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\x64
C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib

You should now be able to compile x64 code using VC 2010 (express).

原文請看http://wiki.codeblocks.org/index.php?title=64Bit_Windows

使用CodeBlocks編譯64位程式(用的編譯器僅僅是windows sdk的)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.