背景: 工作上需要使用MFC/ATL/COM等开发知识,笔记本上只有Linux,VirtualBox上安装Windows没成功,只得曲线救国,通过Wine在Linux平台上学习Windows平台开发知识。Wine是一个有着十多年历史的开源工程,它在Unix平台构建了一个Windows API模拟层以运行Windows程序(而不是像虚拟软件那样模拟硬件资源)。Wine不仅提供了在Linux平台运行Windows程序的工具,还提供了开发库WineLib,这使得在Unix平台开发Windows程序成为可能。这种开发方式是“不实用”的,但对我来说这很重要(也很COOL),因为除了工作的必要,实在不想接触Windows。
首先还是上我的Makefile,一些简单的步骤也包含在这个文件中:
###########################################################################################
# Makefile for MFC Application with wineLib on Linux(Ubuntu 9.10)
# *****************************************************************************************
# * Previous steps:
# * 1. Install wine 1.1.35
# * wget http://ibiblio.org/pub/linux/system/emulators/wine/wine-1.1.35.tar.bz2
# * unzip && ./configure && install
# *
# * Q: configure: error: FreeType development files not found.
# * A:sudo apt-get install libfreetype6-dev
# *
# * 2. Copy all the files of Vistual Studio 6 to wine directory.
# *
# * Notice:
# * When you make with this Makefile at first time,there are some errors about "err:module". Dont worry,make again,you will be success.
# *
# * Creator: think.hy@gmail.com
# * Date: 2010年 01月 03日 星期日 17:20:53 CST
# ****************************************************************************************
WINE = /home/thinkhy/work/wine/wine-1.1.35/wine
LINK = LINK.EXE
LFLAG = /nologo /subsystem:windows #/OPT:REF
CC = CL.EXE
CFLAG = /subsystem:windows /MT #/c /nologo /GX /MT /D "_AFXDLL"
INCLUDE = /I. /I/home/thinkhy/.wine/drive_c/Program/ Files/Microsof/ Visual/ Studio/VC98/Include /
/I/home/thinkhy/.wine/drive_c/Program/ Files/Microsof/ Visual/ Studio/VC98/MFC/Include
LIB = /LIBPATH:/home/thinkhy/.wine/drive_c/Program/ Files/Microsof/ Visual/ Studio/VC98/Lib /LIBPATH:/home/thinkhy/.wine/drive_c/Program/ Files/Microsof/ Visual/ Studio/VC98/MFC/Lib
RES =
SRC = ./test.cpp
OBJ = ./test.obj
OUTFILE = test.exe
OUTPUT = /OUT:$(OUTFILE)
all : link
$(OBJ) : $(SRC)
$(WINE) $(CC) $< $(CFLAG) $(INCLUDE)
link : $(OBJ)
$(WINE) $(LINK) $(LFLAG) $(LIB) $(OBJ) $(RES) $(OUTPUT)
clean:
-rm $(OUTPUT)
touch $(SRC)
###########################################################################################
// 测试代码如下:
class MFC_Tutorial_Window :public CFrameWnd
{
public:
MFC_Tutorial_Window()
{
Create(NULL,"MFC Tutorial Part 1 CoderSource Window");
}
};
class MyApp :public CWinApp
{
MFC_Tutorial_Window *wnd;
public:
BOOL InitInstance()
{
wnd = new MFC_Tutorial_Window();
m_pMainWnd = wnd;
m_pMainWnd->ShowWindow(1);
return 1;
}
CDialog cd;
};
MyApp theApp;
make 之后输出可执行文件test.exe,在Shell运行程序 ./test.exe,效果如下(一个空窗口):