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

45 篇文章 0 订阅
45 篇文章 0 订阅

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

 



// 测试代码如下: 

 #include "AFXWIN.H"

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,效果如下(一个空窗口):

 



 

参考资料:
      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/)       
     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值