提问人:Tom 提问时间:6/20/2021 最后编辑:Tom 更新时间:5/23/2022 访问量:327
无法一致地禁用具有 #pragma 或项目警告级别的标头的 Visual Studio 2019 警告
Cannot consistently disable Visual Studio 2019 warnings for headers with #pragma or project warning level
问:
我正在将 SDL2/GLAD 和 stb_image.h 与 OpenGL 一起使用,但 AFAIK 我的问题与这一事实无关。我正在编辑所有配置下的属性,并且我没有使用预编译的标头。
我想将我的警告级别提高到 /W4 甚至 /Wall。但是,/Wall 给了我多达 1273 个错误,其中大部分来自数学库。因此,我将外部包含包装在 push/pop 指令中,但它似乎什么也没做。具体禁用警告也没有任何作用。glm
#pragma
#pragma warning(disable : n)
当我开始写这个问题时,无论我如何或在哪里放置我的 #pragma 指令(围绕标头、在标头内、围绕函数、围绕调用),或者我是否将项目警告级别设置为从 /W0 到 /W4 的任何位置,大约 80 个错误都会偷偷溜走:一个来自 SDL2,其余来自 .但是,在测试过程中,我的错误列表可能会在 ~7 个错误之间跳转,从备份到 70+。stb_image.h
stb_image.h
我正在努力寻找 Visual Studio 处理错误的方式的任何一致性。我只想关闭来自外部标头和库的错误,这样我只能看到我编写的代码中的错误。我做错了什么?
#pragma warning(push, 0)
#include <glad/glad.h>
#include <SDL.h>
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image/stb_image.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#pragma warning(pop)
#include <iostream>
#include <vector>
#include <fstream>
// ...
Image LoadTexture(const std::string& path, GLenum format) {
int width, height, channels;
unsigned char* data = stbi_load(path.c_str(), &width, &height, &channels, STBI_default);
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if (data) {
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
}
else {
std::cerr << "Failed to load texture " << path << std::endl;
texture = -1; // error
}
stbi_image_free(data);
return { texture, width, height, channels };
}
// ...
答:
评论
#pragma push
pop