window下通过makefile 文件编译C/C++源文件(Scintilla的windows例子)

来源:互联网 发布:网络剧女娲成长日记 编辑:程序博客网 时间:2024/06/06 05:30

今天从网上下载了一个Scintilla的例子,发现里面所带的C++窗口例子是通过makefile文件进行编译的,以前编译都是通过IDE环境,配置好后进行编译的,还真没用过makefile编译过文件,于是在网上找了个例子,通过实验终于完成了编译,现在把其中的方法记录下来,作为积累吧

scintilla下载下来的例子:dmapp
所带4文件,一个空文件夹(无用好像):
resource.h
DMApp.cxx
DMApp.rc
makefile_vc

其中
makefile_vc的文件内容:
/////////////////////////////////////////////////////////////////////////
# Make file for DMApp, a small demonstration application
# for the SciLexer DLL.
# This file should be in a directory which is a peer of the scintilla
# directory so Scintilla.h and SciLexer.h files can be found

CC = cl
RC = rc
LD = link

O = obj

PROGDEMO = DMApp.EXE

ALL:    $(PROGDEMO)

clean:
    del /q *.exe *.obj *.res

LDFLAGS = /NODEFAULTLIB:LIBC KERNEL32.lib USER32.lib GDI32.lib COMDLG32.lib WINMM.lib COMCTL32.lib ADVAPI32.lib IMM32.lib SHELL32.LIB OLE32.LIB
CXXFLAGS = /TP /MD /Ox

!IFDEF DEBUG
CXXFLAGS=$(CXXFLAGS) /Zi
LDFLAGS=/DEBUG $(LDFLAGS)
!ENDIF

.cxx.$(O):
    $(CC) /I ../scintilla/include $(CXXFLAGS) -c $*.cxx -o $@

.rc.res:
    $(RC) $*.rc
   
DMApp.o: Scintilla.h SciLexer.h resource.h

$(PROGDEMO):    DMApp.obj DMApp.res
    $(LD) DMApp.obj DMApp.res $(LDFLAGS)

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

其中../scintilla/include为scintilla包含的头文件所在目录

接下来

制作编译处理文件 run.bat
---------------------------------
nmake -f makefile_vc LINK_LIB="SciLexer.lib"
PAUSE
@set PATH=/; %path%
error_printer | tee2.5.exe result.rst
PAUSE

-----------------------------
其中 makefile_vc 为makefile的文件名, SciLexer.lib 为所需要的库,如果包含多个库可以设置成路径目录

运行run.bat编译结果:

--------------------------------------------------------------------------

F:/dmapp>nmake -f makefile_vc LINK_LIB="SciLexer.lib"

Microsoft (R) Program Maintenance Utility   Version 6.00.9782.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.

        cl /I inc /TP /MD /Ox -c DMApp.cxx -o DMApp.obj
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

DMApp.cxx
        rc DMApp.rc
        link DMApp.obj DMApp.res /NODEFAULTLIB:LIBC KERNEL32.lib USER32.lib GDI3
2.lib COMDLG32.lib WINMM.lib COMCTL32.lib ADVAPI32.lib IMM32.lib SHELL32.LIB OLE
32.LIB
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


F:/dmapp>PAUSE
请按任意键继续. . .

---------------------------------
good !

原创粉丝点击