Use nmake to program c ++

Source: Internet
Author: User

Recently, I read c ++ primer 5 and found that the nmake tool of vc11 is used to compile files. Similar to the makefile tool in Linux, it is easy to clear and compile files with one click. You just want to compile some small code segments using this method, so you don't have to open the bulky vs2012.

Use the CL command line to compile the program:

Write a simple bat script to find the configuration file of the VC environment variable:

@echo offcall "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\vsvars32.bat"call NMAKEcmd 

Use CL command lines to compile C ++ files:

cl /EHsc /nologo /I.. filname.cpp

Nmake actually calls CL in batches to compile the link target file.

The following describes how to configure makefile.

A simple makefile example is used to compile the wordcount. CC file:

CPP = clCPPFLAGS = /EHsc /nologo /I.. $(LOCFLAGS)LOCFLAGS = -I..\7 -I..\6OBJECTS = WordCount.exeall: $(OBJECTS) .cpp.obj: $(CPP) $(CPPFLAGS) /c $< .obj.exe:$(CPP) $(CPPFLAGS) $<clean:del *.obj core *.stackdumpclobber: cleandel *.exe 

Write a BAT file and call makefile:

@echo offcall "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\vsvars32.bat"call nmake -nologocmd 

Or add vsvar to the environment variable and open CMD in this folder:

Compile: cmd: nmake

Clear: cmd: nmake clean

Delete: cmd: nmake clobber

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.