undefined reference to `glad_glBegin'
时间: 2023-10-13 13:24:38 浏览: 218
This error message typically indicates that your code is not properly linked to the GLAD library. GLAD is a library that generates function pointers for OpenGL, and it needs to be initialized before you can use OpenGL functions.
To fix this error, make sure that you have properly included the GLAD header file in your code and linked against the GLAD library. Here are some steps you can follow:
1. Download the GLAD library from the official website: https://glad.dav1d.de/
2. Select the OpenGL version and profile that you want to use, and make sure to select "C/C++" as the language.
3. Click "Generate" to download a ZIP file containing the GLAD header and source files.
4. Extract the ZIP file and copy the "glad.h" header file and the "glad.c" source file into your project directory.
5. In your code, include the "glad.h" header file before any other OpenGL headers, and add the following line after your OpenGL context is created:
```
if (!gladLoadGL()) {
// Handle error
}
```
This will initialize GLAD and load all the necessary OpenGL function pointers.
6. Finally, make sure to link against the GLAD library when building your project. On Linux, you can add "-lglad" to your linker flags. On Windows, you can add "glad.c" to your project and compile it with your code.
If you're still having trouble, double-check that you've correctly followed all the steps and that your build environment is set up correctly.
阅读全文