`
lovecontry
  • 浏览: 1033523 次
文章分类
社区版块
存档分类
最新评论

[技术学习]在Linux平台学习Windows开发技术(一)----编译第一个MFC程序

 
阅读更多

背景: 工作上需要使用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
# *wgethttp://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 installlibfreetype6-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)
###########################################################################################



// 测试代码如下:

#include "AFXWIN.H"

classMFC_Tutorial_Window :publicCFrameWnd
{
public:
MFC_Tutorial_Window()
{
Create(
NULL,"MFC Tutorial Part 1 CoderSource Window");
}
};

classMyApp :publicCWinApp
{
MFC_Tutorial_Window *wnd;
public:
BOOL InitInstance()
{
wnd =
newMFC_Tutorial_Window();
m_pMainWnd = wnd;
m_pMainWnd->ShowWindow(
1);
return1;
}
CDialog cd;
};

MyApp theApp;




make 之后输出可执行文件test.exe,在Shell运行程序 ./test.exe,效果如下(一个空窗口):



参考资料:
1. [原创]在linux系统中编写windows程序并连接成二进制文件(http://forum.ubuntu.org.cn/viewtopic.php?f=88&t=96015&view=next)
2. 使用 wine 进行 WIN32/MFC 开发 (http://shuizhuyuanluo.blog.163.com/blog/static/77818120091030113223845/)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics