[英]Cannot consistently disable Visual Studio 2019 warnings for headers with #pragma or project warning level
I am using SDL2/GLAD and stb_image.h with OpenGL, but AFAIK my problem is independent of that fact.我将 SDL2/GLAD 和stb_image.h与 OpenGL 一起使用,但我的问题与该事实无关。 I am editing properties under all configuration and I am not using precompiled headers.
我正在编辑所有配置下的属性,并且我没有使用预编译的头文件。
I want to up my warning level to /W4 or even /Wall.我想将警告级别提高到 /W4 甚至 /Wall。 However, /Wall gives me up to 1273 errors, most from the math library
glm
.但是, /Wall 给我最多 1273 个错误,大部分来自数学库
glm
。 So, I wrapped my external includes in a #pragma
push/pop directive, but it seems to do absolutely nothing.所以,我将我的外部包含包装在
#pragma
push/pop 指令中,但它似乎什么也没做。 Specifically disabling warnings with #pragma warning(disable : n)
does nothing either.使用
#pragma warning(disable : n)
专门禁用警告也无济于事。
When I started writing this question, no matter how or where I placed my #pragma directives (around headers, within headers, around functions, around calls), or whether I had my project warning level set anywhere from /W0 to /W4, about 80 errors would sneak through: one from SDL2, and the rest from stb_image.h
.当我开始写这个问题时,无论我如何或在何处放置我的#pragma 指令(围绕标题、在标题内、围绕函数、围绕调用),或者我是否将我的项目警告级别设置为从 /W0 到 /W4 的任何位置,大约80 个错误会潜入:一个来自 SDL2,其余来自
stb_image.h
。 However, randomly during testing, my error list can jump between ~7 errors from stb_image.h
back up to 70+.但是,在测试期间随机,我的错误列表可以在从
stb_image.h
到 70+ 的 ~7 个错误之间跳转。
I'm struggling to find any consistency in how Visual Studio handles errors.我正在努力寻找 Visual Studio 如何处理错误的一致性。 I just want to turn off errors from external headers and libraries so I can only see errors from code I have written.
我只想关闭来自外部头文件和库的错误,所以我只能看到我编写的代码中的错误。 What am I doing wrong?
我究竟做错了什么?
#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 };
}
// ...
This is probably because of IntelliSense, it seems to ignore "#pragma warning(push, 0)"这可能是因为 IntelliSense,它似乎忽略了“#pragma warning(push, 0)”
IntelliSense is very unstable (and we are in year 2022 already!) IntelliSense 非常不稳定(我们已经到了 2022 年!)
What solved the problem for me is to select "Build Only" in the listbox, as the print bellow:为我解决问题的是在列表框中选择“仅构建”,如下所示:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.