Code::Blocks undefined reference to “*” [duplicate]

有些话、适合烂在心里 提交于 2019-12-11 08:15:59

问题


Like the title says, I'm getting multiple build errors using C::B, all are saying undefined reference to '*'. I'm trying to build a program using OpenGL, GLFW, and GLEW. The top three things that it cant find every time are _imp__CreateDCW@16, _imp__GetDeviceCaps@8, _imp__DeleteDC@4. When looking on the internet, I saw that all of those methods were in the gdi32 library, which I made sure to add to the linker. The error appears to be happening as soon as I try to use methods from GLFW3. I've tried using different builds of GLFW using MinGW, which is what I'm using with Code::Blocks, but I cannot get the error to go away.

I am developing on Windows 8.1, using Code::Blocks 13.12.

Here is a list of everything I am linking and in the same order:

  • gdi32
  • kernel32
  • user32
  • opengl32
  • glu32
  • glfw3

Code::Blocks is turning out to be a bit of a hassle, but I really want to start to get used to it. Thanks to anyone who can help.


回答1:


You've to pass -lgdi32 for the linker to know that you're using GDI functions. Also the order matters. On Windows 8 with MinGW 4.8.1 tool chain I give this:

  • glew
  • glfw3
  • opengl32
  • gdi32

And it works for me; I don't include the other win32 libraries. If you're using GLEW's static library make sure you define GLEW_STATIC either in CB or directly as -DGLEW_STATIC.

As for the IDE, I chose QtCreator with CMake and with no Qt SDK.



来源:https://stackoverflow.com/questions/22824709/codeblocks-undefined-reference-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!