Windows 下 C++ primer 5 代码编译 ( namke )

C++ primer 源码下载:https://www.informit.com/store/c-plus-plus-primer-9780321714114 选择  “Download the source code files for MS Visual Studio 2012

下载的源码文件夹(局部):

 Visual Studio 2012 README.pdf  提示的编译命令:

# Windows machines
> nmake # compiles all the programs
> nmake clean # removes all the object files and stackdumps
> nmake clobber # removes executable, object and stackdump files

nmake 相当于l inux 中的make, 会调用源码目录的 makefile 进行编译工作。但是 命令提示符 ( cmd )窗口 不能直接执行 nmake , 需要配置一番,调用 Visual Studio 的编译工具。 详情见  从命令行使用 Microsoft C++ 工具集 ,电脑未安装 visual studio 的可以安装 专门的 组件,也可以 直接装 visual studio 。

 

编译环境配置:

 法 一 :

源码根目录编写 compille64.bat ,内容:( vcvars64.bat 路径需要根据 实际情况更改)

@echo off
call "F:\VisualStudio2022Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cmd

vcvars64.bat   用于原编译平台是 64位 目标平台也是 64位 ( 记录:vcvars64.bat 会调用 VsDevCmd.bat)。也可以选择与 vcvars64.bat 同路径的其他几个:

 

它们的区别是:

命令文件主机和目标架构
vcvars32.bat 使用 32 位 x86 原生工具构建 32 位 x86 代码。
vcvars64.bat 使用 64 位 x64-native 工具构建 64 位 x64 代码。
vcvarsx86_amd64.bat 使用 32 位 x86-native 交叉工具构建 64 位 x64 代码。
vcvarsamd64_x86.bat 使用 64 位 x64-native 交叉工具构建 32 位 x86 代码。
vcvarsall.bat 使用参数来指定主机和目标体系结构、Windows SDK 和平台选择。有关支持的选项列表,请使用/help参数调用。

 

 

法 二:

编写  compile.bat 直接调用 VsDevCmd.bat :(VsDevCmd.bat 需根据实际情况更改)

@echo off
call "F:\VisualStudio2022Enterprise\Common7\Tools\VsDevCmd.bat"
cmd

开发人员命令提示符命令文件 VsDevCmd.bat 位于Common7\Tools子目录中。未指定参数时,它将环境设置为使用 x86-native 工具构建 32 位 x86 代码。

 

执行编译:

双击 写好的 compile 64.bat  或者 compile.bat 文件 在 唤起的 cmd 窗口执行 nmake 命令。

 

 

相关内容备忘录:

CD [/D] [drive:][path]

E:\C++Project\C++Primer5\1\chapter1\x64\Debug>chapter1 <book_sales >outfile

 

posted @ 2022-05-11 12:45  星云体  阅读(188)  评论(0编辑  收藏  举报