如何解决未定义的引用,库是否未导入或其他问题

时间:2019-05-10 10:54:51

标签: win32gui

我试图在一个项目上使用Win32 GUI项目,但是当我对其进行编译时,会出现很多未定义的引用错误。

  

|| ===构建:最终在05.9。中进行调试(编译器:GNU GCC编译器)=== |   obj \ Debug \ main.o ||在函数Z4OpenP6HWND__':| C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|61|undefined reference to wglCreateContext @ 4'|中   C:\ Users \ Administrator \ Desktop \计算机图形\ 05.9.finally \ main.cpp | 63 |未定义   参考wglMakeCurrent@8'| C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|65|undefined reference to glClearColor @ 16'| obj \ Debug \ main.o ||在函数中   Z4Initv':| C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|76|undefined reference to glBlendFunc @ 8'|   C:\ Users \ Administrator \ Desktop \计算机图形\ 05.9.finally \ main.cpp | 77 |未定义   引用到glClearColor@16'| C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|78|undefined reference to glClearDepth @ 8'|   C:\ Users \ Administrator \ Desktop \计算机图形\ 05.9.finally \ main.cpp | 79 |未定义   参考glDepthFunc@4'| C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|80|undefined reference to glEnable @ 4'|   C:\ Users \ Administrator \ Desktop \计算机图形\ 05.9.finally \ main.cpp | 81 |未定义   对glShadeModel@4'| C:\Users\Administrator\Desktop\计算机图形\05.9.finally\main.cpp|82|undefined reference to glHint @ 8'|的引用obj \ Debug \ main.o ||在函数“ Z6Draw3Dv”中:|

#include <GL/gl.h>
#include <GL/glut.h>
#include <windows.h>
GLfloat step = 0.0f;

HINSTANCE hInstance;                                         // 系统实例句柄
HWND      hWndMain;                                          // 主窗体句柄
HWND      hWnd;                                              // 窗体句柄变量定义
HDC       hDC;                                               // 设备描述表变量定义
PIXELFORMATDESCRIPTOR pfd;                                   // 像素格式结构变量定义
HGLRC     hGLRC;                                             // OpenGL渲染描述表变量定义

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);        // 窗体过程函数声明

GLboolean keys[256];
GLfloat rotStep = 30.0f;
void keyPress();


GLuint Open(HWND phWnd)

{
      hWnd = phWnd;

      hDC = GetDC(hWnd);

      pfd.dwDamageMask    = 0;                       // 忽略层遮罩

      int pixelformat = ChoosePixelFormat(hDC, &pfd);

      SetPixelFormat(hDC, pixelformat, &pfd);

      hGLRC = wglCreateContext(hDC);

      wglMakeCurrent(hDC,hGLRC);

      glClearColor(0.0f, 0.0f, 0.0f, 1.0f);          // 初始化背景为灰色

      return 0;
}

2 个答案:

答案 0 :(得分:0)

您在名称中包含正斜杠。也许您想要#include“路径/名称”。

答案 1 :(得分:0)

我相信您现在已经解决了;如果不是这样,您可以尝试提供正确的库路径。编译/链接时,使用命令行选项-L到库文件夹的路径,并使用-l作为库名。

对OpenGL的在线查找表明,库文件名可以是以下任意一个或全部:opengl32.a or opengl32.libglu32.a or glu32.libfreeglut.a or freeglut.lib(如果您使用的是.a,请选择{ Linux或Windows上的.lib