IT

Visual Studio에서 기본적으로 프로젝트에서 보안 경고 (_CRT_SECURE_NO_WARNINGS) 제거

lottoking 2020. 5. 27. 07:58
반응형

Visual Studio에서 기본적으로 프로젝트에서 보안 경고 (_CRT_SECURE_NO_WARNINGS) 제거


scanf ()와 같은 함수를 사용할 때 발생하는 프리 컴파일러 보안 경고를 제거하는 모든 프로젝트에 기본적으로 설정하는 방법이 있습니까? 프로젝트 옵션 또는 #define _CRT_SECURE_NO_WARNINGS코드 시작 부분에 줄을 추가하여 할 수 있음을 발견했습니다 .

나는 프로그래밍 콘테스트를 해결하기 위해 새로운 프로젝트를 반복해서 만들고 있으며 추가하는 것은 정말 성가신 일이며 귀중한 시간이 걸립니다.

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

코드의 시작 부분에서 또는 새 프로젝트를 시작할 때마다 프리 컴파일러 옵션에서 설정합니다.


솔루션 탐색기에서 원하는 모든 프로젝트를 표시하십시오.

Alt-F7을 누르거나 솔루션 탐색기에서 마우스 오른쪽 버튼을 클릭하고 "속성"을 선택하십시오.

구성 : 모든 구성

프리 프로세서 정의 행을 클릭하여 편집기를 호출하십시오.

편집 ...을 선택하십시오.

"_CRT_SECURE_NO_WARNINGS"를 상단의 전 처리기 정의 흰색 상자에 복사하십시오.

여기에 이미지 설명을 입력하십시오


VS에 익숙하지 않고 C에 익숙하지 않기 때문일 수 있지만, 내가 만들 수 있었던 유일한 것은 추가하는 것입니다.

#pragma warning(disable:4996)

내 파일 상단에서 sprintf로 인한 C4996 오류를 억제했습니다.

약간 성가 시지만 내 작은 코드에 가장 적합합니다.

나는 그것에 대해 읽었습니다 : https://msdn.microsoft.com/en-us/library/2c8f766e.aspx


자동적으로 아닙니다. 당신은 프로젝트 템플릿을 생성 할 수 있습니다 BlueWandered이 제안 또는 당신이 당신의 현재와 미래의 모든 프로젝트에 사용할 수있는 사용자 정의 속성 시트를 만들 수 있습니다.

  1. 속성 관리자를 엽니 다 (보기-> 속성 관리자)
  2. In the Property Manager Right click on your project and select "Add New Project Property Sheet"
  3. Give it a name and create it in a common directory. The property sheet will be added to all build targets.
  4. Right click on the new property sheet and select "Properties". This will open up the properties and allow you to change the settings just like you would if you were editing them for a project.
  5. Go into "Common Properties->C/C++->Preprocessor"
  6. Edit the setting "Preprocessor Definitions" and add _CRT_SECURE_NO_WARNINGS.
  7. Save and you're done.

Now any time you create a new project, add this property sheet like so...

  1. Open up the Property Manager (View->Property Manager)
  2. In the Property Manager Right click on your project and select "Add Existing Project Property Sheet"

The benefit here is that not only do you get a single place to manage common settings but anytime you change the settings they get propagated to ALL projects that use it. This is handy if you have a lot of settings like _CRT_SECURE_NO_WARNINGS or libraries like Boost that you want to use in your projects.


All the solutions here failed to work on my VS2013, however I put the #define _CRT_SECURE_NO_WARNINGS in the stdafx.h just before the #pragma once and all warnings were suppressed. Note: I only code for prototyping purposes to support my research so please make sure you understand the implications of this method when writing your code.

Hope this helps


my two cents for VS 2017:

I can confirm it works in stdafx.h both in these styles:

a)

#pragma once
#define _CRT_SECURE_NO_WARNINGS 1 
#define _WINSOCK_DEPRECATED_NO_WARNINGS 1 

b)

#define _CRT_SECURE_NO_WARNINGS 1 
#define _WINSOCK_DEPRECATED_NO_WARNINGS 1 
#pragma once

(I have added another define for MSDN network calls..) Of course I do prefer a).

I can confirm that: #define _CRT_SECURE_NO_WARNINGS (without a value) DOES NOT WORK.

PS the real point is to put these defines BEFORE declarations of functions, i.e. before *.h


just copy " _CRT_SECURE_NO_WARNINGS " paste it on projects->properties->c/c++->preprocessor->preprocessor definitions click ok.it will work


If your project does not use stdafx.h, you can put the following lines as the first lines in your .cpp file and the compiler warning should go away -- at least it did for me in Visual Studio C++ 2008.

#ifdef _CRT_SECURE_NO_WARNINGS
#undef _CRT_SECURE_NO_WARNINGS
#endif
#define _CRT_SECURE_NO_WARNINGS 1

It's ok to have comment and blank lines before them.


_CRT_SECURE_NO_WARNINGS 를 프로젝트의 속성에 추가 할 수 있지만 가장 쉬운 방법은 stdafx.h를 사용하여 모든 종류의 경고 및 오류를 비활성화하는 것입니다.

#pragma once

또한 _CRT_SECURE_NO_WARNINGS에 대한 값 (예 : "1")을 정의 할 필요가 없습니다. 따라서 다음과 같아야합니다.

#define _CRT_SECURE_NO_WARNINGS 

#pragma once

참고 URL : https://stackoverflow.com/questions/16883037/remove-secure-warnings-crt-secure-no-warnings-from-projects-by-default-in-vis

반응형