如何防止Visual Studio项目设置覆盖命令行SET CL选项

时间:2017-12-06 08:06:20

标签: c++ visual-studio visual-studio-2012 visual-studio-2015 cl

我需要使用Visual Studio 2015构建一个Visual Studio 2012项目,并且发现Visual Studio 2015似乎已经更改了规则,现在Windows API函数被认为已弃用。我发现我可以使用SET CL通过命令行更改编译选项,但是这个命令行选项正在被覆盖。

我需要找到一种方法来强制使用命令行选项。

以下是源代码:

/*
1>e:\code\compile_cmd_line\main.cpp(15): warning C4996: 'GetVersionExA': was declared deprecated
1>  c:\program files (x86)\windows kits\8.1\include\um\sysinfoapi.h(433): note: see declaration of 'GetVersionExA'
*/

// with below line uncommented, builds in Visual Studio 2015 IDE ok
// #pragma warning(disable: 4996)  // error C4996: 'GetVersionExA': was declared deprecated

#include <windows.h>

int main() {
    OSVERSIONINFOA vi = { };
    BOOL ret = GetVersionExA(&vi);
}

项目文件中的编译器选项是:

/GS /GL /analyze- /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"Release\vc140.pdb" /Zc:inline /fp:precise /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MD /Fa"Release\" /EHsc /nologo /Fo"Release\" /Fp"Release\compile_cmd_line.pch"

问题设置是SDL检查/ sdl和安全检查/ GS

以下是我尝试使用VS2015进行编译的方法:

E:\code\compile_cmd_line>set CL=/sdl- /GS-

E:\code\compile_cmd_line>devenv /useenv /build "Release|x86" compile_cmd_line.sln

Microsoft Visual Studio 2015 Version 14.0.25420.1.
Copyright (C) Microsoft Corp. All rights reserved.

The license for Visual Studio expires in 20 days.
1>------ Build started: Project: compile_cmd_line, Configuration: Release Win32
------
1>cl : Command line warning D9025: overriding '/sdl-' with '/GS-'
1>cl : Command line warning D9025: overriding '/GS-' with '/sdl'
1>  main.cpp
1>main.cpp(20): error C4996: 'GetVersionExA': was declared deprecated
1>  C:\Program Files (x86)\Windows Kits\8.1\include\um\sysinfoapi.h(433): note:
see declaration of 'GetVersionExA'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

E:\code\compile_cmd_line>

问题在于:

1>cl : Command line warning D9025: overriding '/sdl-' with '/GS-'
1>cl : Command line warning D9025: overriding '/GS-' with '/sdl'

为了完整起见,我有一个设置脚本来设置MS构建工具的env变种:

call "%VS140COMNTOOLS%vsvars32.bat"

set INCLUDE=C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt;%INCLUDE%
set LIB=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x86;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x86;%LIB%

有更好的方法吗?

我可以使用SET CL强制覆盖吗?

0 个答案:

没有答案