![](/img/trans.png)
[英]Visual Studio build vs intellisense warnings. What is the difference, and why does pragma warning(disable) not remove intellisense warning?
[英]Cannot consistently disable Visual Studio 2019 warnings for headers with #pragma or project warning level
我將 SDL2/GLAD 和stb_image.h與 OpenGL 一起使用,但我的問題與該事實無關。 我正在編輯所有配置下的屬性,並且我沒有使用預編譯的頭文件。
我想將警告級別提高到 /W4 甚至 /Wall。 但是, /Wall 給我最多 1273 個錯誤,大部分來自數學庫glm
。 所以,我將我的外部包含包裝在#pragma
push/pop 指令中,但它似乎什么也沒做。 使用#pragma warning(disable : n)
專門禁用警告也無濟於事。
當我開始寫這個問題時,無論我如何或在何處放置我的#pragma 指令(圍繞標題、在標題內、圍繞函數、圍繞調用),或者我是否將我的項目警告級別設置為從 /W0 到 /W4 的任何位置,大約80 個錯誤會潛入:一個來自 SDL2,其余來自stb_image.h
。 但是,在測試期間隨機,我的錯誤列表可以在從stb_image.h
到 70+ 的 ~7 個錯誤之間跳轉。
我正在努力尋找 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 };
}
// ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.