1. 程式人生 > >使用CodeBlocks編譯64位程序(用的編譯器僅僅是windows sdk的)

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

click wiki Once eas star global microsoft x86 href

需求:

-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的)