undefined reference to `glad_glBegin' opengl4
时间: 2023-10-21 15:18:52 浏览: 108
OpenGL glad
3星 · 编辑精心推荐
This error occurs when the linker is unable to find the definition of the function `glad_glBegin` in your code.
To resolve this issue, you need to ensure that you have properly linked the OpenGL library and that your code includes the necessary headers. Here are some steps you can follow:
1. Make sure that you have included the appropriate OpenGL headers in your code. For example, you may need to include the following header:
```c++
#include <glad/glad.h>
```
2. Ensure that you have properly linked the OpenGL library. You can do this by adding the following line to your CMakeLists.txt file (or equivalent build system file):
```cmake
target_link_libraries(your_project_name PRIVATE opengl32)
```
Note that the library name may be different depending on your platform.
3. Make sure that you have initialized the GLAD library before calling any OpenGL functions. You should call `gladLoadGL()` after creating an OpenGL context. Here's an example:
```c++
if (!gladLoadGL()) {
std::cerr << "Failed to initialize GLAD" << std::endl;
exit(EXIT_FAILURE);
}
```
4. Check that you are using the correct function name. In this case, `glad_glBegin` should be `glBegin`.
By following these steps, you should be able to resolve the undefined reference to `glad_glBegin` error and successfully compile your code.
阅读全文