c - GCC 编译器给了我关于 true 未定义等错误
问题描述
我想用 OpenGL 制作一个游戏,到目前为止它给了我这些错误。这没有多大意义,因为我遵循了一个教程(这是一个 C++ 教程,但几乎相同)
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glfw3.h>
int main(){
glewExperimental = true;
if(!glfwInit()){
printf("failed to initialize GLFW\n");
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTENT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window;
window = glfwCreateWindow(1024, 768, "Game", NULL, NULL);
if(window == NULL){
printf("Sorry to say this, but your OpenGL version must be 3.3 or above! Thanks for playing, but to continue you must update your video card drivers or if you use an old GPU you may have to replace it with a new one to play this game. I will be developing my game for OpenGL 1 and 2 soon so stay on touch.");
glfwTerminate();
return -1;
}
glfwMakeContentCurrent(window);
glewExperimental = true;
if(glewInit() != GLEW_OK){
printf("Failed to initilize GLEW");
return -1;
}
}
这些是错误:
main.c: In function ‘main’:
main.c:7:23: error: ‘true’ undeclared (first use in this function)
7 | glewExperimental = true;
| ^~~~
main.c:7:23: note: each undeclared identifier is reported only once for each function it appears in
main.c:14:19: error: ‘GLFW_CONTENT_VERSION_MINOR’ undeclared (first use in this function); did you mean ‘GLFW_CONTEXT_VERSION_MINOR’?
14 | glfwWindowHint(GLFW_CONTENT_VERSION_MINOR, 3);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
| GLFW_CONTEXT_VERSION_MINOR
main.c:25:4: warning: implicit declaration of function ‘glfwMakeContentCurrent’; did you mean ‘glfwMakeContextCurrent’? [-Wimplicit-function-declaration]
25 | glfwMakeContentCurrent(window);
| ^~~~~~~~~~~~~~~~~~~~~~
| glfwMakeContextCurrent
编辑:事实证明我有一个错字。它必须是 GLFW_CONTEXT_VERSION_MINOR 而不是 GLFW_CONTENT_VERSION_MINOR
解决方案
如果编译为 C,您必须#include <stdbool.h>
访问true
,false
和bool
. 它们只是 C++ 中的关键字,而不是 C 中的关键字。
推荐阅读
- c# - 如何从不同的线程调用方法
- html - 为什么 bootstrap 有一个 navbar-nav 标记通常使用无序列表作为链接?
- xml - XQuery:预期的“返回”发现“if(”错误
- html - 如何防止弹性项目在没有包装的情况下溢出弹性父项?
- javascript - 交换字符串中单词的最佳方法是什么
- c# - c#WPF'名称空间中不存在名称xxx-我缺少什么?
- java - 如何将char转换为unicode java
- ios - 自定义 UICollectionView 包装其自调整大小的单元格
- sas - SAS 阵列创建
- c# - 如何在 asp.net mvc 的弹出窗口中创建一个空表单?