Thứ Ba, 16 tháng 8, 2011

Lỗi thiếu thư viên của DirectX với ứng dụng T3DConsole2 trong chương 3

Trước tiên, để có thể lập trình với thư viện DirectX, ta cần có một bộ thư viên Microsoft DirectX SDK được cài đặt trên máy. Cái này có thể download trên trang của Microsoft, dung lượng trên dưới 400MB.

Bước kế tiếp ta phải thêm tùy cho cho môi trường Microsoft Visual C++ 2008 biết được đường dẫn đến các thư mục liên quan đến DirectX như sau:

Chọn Tools\Options\Projects and Solutions\VC++ Directories
- Trong mục Executable Files ta thêm đường dẫn đến ....\Microsoft DirectX SDK (2010)\Utilities\Bin\x86
- Trong mục Include Files ta thêm đường dẫn đến ....\Microsoft DirectX SDK (2010)\Include
- Trong mục Library Files ta thêm đường dẫn đến ....\Microsoft DirectX SDK (2010)\Lib\x86

Do các chương trình mẫu trong CD được tác giả xây dựng với DirectX 9cho nên khi ta build va compile những chưng trình này với bộ DirectX mới chắc chắn sẽ có lỗi xảy ra. Nguyên nhân do, một số Files.h cũng như File.Lib (một số COMponent) trong bộ DirectX 2010 không còn hổ trợ nữa. Vì vậy, khi ta build thử ứng dụng "T3DConsole2" sẽ bắt gặp lỗi.

1) Download các File.h  và bỏ vào thư mục ....\Microsoft DirectX SDK (2010)\Include gồm: dls1.h
dmdls.h
dmerror.h
dmksctrl.h
dmplugin.h
dmusbuff.h
dmusicc.h
dmusicf.h
dmusici.h
//======================================
Mình fixed được lỗi này nhờ thông tin từ một Entry trên diễn đàn như sau:

Microsoft® DirectX SDK earlier than August 2007

Information: The DirectX SDK from November 2007 is the first one which supports Microsoft® Visual Studio 2008. But it's also the first version which doesn't support DirectMusic which is needed to compile OpenTTD. That is why we must copy the missing files from an older version, prefered the final one for DirectMusic: 'August 2007'.
Extract (no double-click, do not install) dxsdk_aug2007.exe in an extra directory and you get a file called dxsdk_aug2007.exe (yes that's right, both files have the same name).
Extract the second dxsdk_aug2007.exe in an extra directory.
Now copy following 9 files from .\dxsdk_aug2007\dxsdk_aug2007\Include\ to <personal folder>\shared\include (note: Please update the paths as necessary):

//============================================

2) DirectX SDK 2010 không còn cung cấp thư viện DDraw.lib nhưng ta có thể tìm được DDraw.h nhờ Windows SDK có cung cấp file.h này .Do đó khi ta Build ứng dụng sẽ gặp lỗi. Cách làm đơn giản là Download DDraw.lib và bỏ vào thư muc \Microsoft DirectX SDK (2010)\Lib\x86. Mình nghĩ DDraw.DLL sẽ có sẵn trong thư mục System32\ nên ta không cần download thư mục này.

//===========================================

Mình fixed được lỗi này nhờ thông tin từ một Entry trên diễn đàn như sau:
Hi Jaki,

As far as I know, we can get ddraw.h from Windows SDK, but not ddraw.lib. Ddraw.lib comes from Windows SDK or Windows DDK. See the information from http://blogs.msdn.com/b/chuckw/archive/2010/06/16/wither-directdraw.aspx

In the DirectX SDK (June 2010) release, the DDRAW.H and DDRAW.LIB files are no longer there. The latest version of DirectX SDK which contains the ddraw.lib is February 2010, you can download it from http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=2c7da5fb-ffbb-4af6-8c66-651cbd28ca15

Hope this information helps.

Cheers,
Yi
//===========================================


3) Một lỗi nữa chắc chắn gặp phải đó là:
error LNK2019: unresolved external symbol.....
error LNK2019: unresolved external symbol.....
error LNK2019: unresolved external symbol.....
error LNK2019: unresolved external symbol.....
error LNK2019: unresolved external symbol.....
Lỗi này xẩy ra không quá trình Compiling. Nguyên nhân là do các File.Obj như T3DLib1.Ojb, T3DLib2.Ojb, T3DLib3.Ojb không link được với mã nguồn chứa các function thực.
Cách sửa lỗi cũng khá đơn giản. Chúng ta hãy Link các thư viên dxguid.lib dsound.lib dinput8.lib d3d10.lib winmm.lib trước khi biên dịch. Cách làm như sau:

Solution: include Linker as:
Project\Properties\Linker\Commandline\Additional Option
dxguid.lib dsound.lib dinput8.lib d3d10.lib winmm.lib


Trên đây là 3 lỗi mình đã gặp phải khi Build up ứng dụng mẫu của cuốn sách "Tricks of the 3D Game Programming Gurus" với trình biên dịch Microsoft Visual C++ 2008 và bộ Microsoft DirectX SDK (2010).

Good luck!

Không có nhận xét nào:

Đăng nhận xét