1

I get a 9 unresolved external symbol errors when I try to compile my VS 2015 C++ project. The errors occurred when I tried to compile GLEW as part of my project (using the source code). A Google search shows that this error is usually caused by missing OpenGL libraries, but I am already using SDL2, which, as far as I know, contains OpenGL in its source code. This is the output when I try to compile.

Error   LNK2001 unresolved external symbol __imp__wglGetCurrentDC@0 glew.obj    1   
Error   LNK2001 unresolved external symbol __imp__wglGetProcAddress@4   glew.obj    1   
Error   LNK2001 unresolved external symbol __imp__glGetString@4 glew.obj    1   
Error   LNK2001 unresolved external symbol __imp__glGetIntegerv@8   glew.obj    1   
Error   LNK2001 unresolved external symbol __imp__wglCreateContext@4    glewinfo.obj    1   
Error   LNK2001 unresolved external symbol __imp__wglDeleteContext@4    glewinfo.obj    1   
Error   LNK2001 unresolved external symbol __imp__wglMakeCurrent@8  glewinfo.obj    1   
Error   LNK2001 unresolved external symbol __imp__wglGetCurrentContext@0    visualinfo.obj  1   
Error   LNK2001 unresolved external symbol _gluGetString@   4visualinfo.obj     1   
Error   LNK1120 9 unresolved externals  Executable.exe  1   

If there is another library that I need to include in my project, where can I download it? Also, if there is, does it have source code? I would prefer to avoid .dlls if possible.

EDIT: This is not just a general example of an unresolved external symbol. I was asking about what libraries I would need to include to fix the error.

1 Answers1

1

To compile GLEW as source files added to your project, use the following steps:

  1. The only file required is glew.c. Remove glewinfo.c and visualinfo.c - these are just example programs supplied with GLEW. This step will resolve the missing glu* symbols.

  2. Add GLEW_STATIC to list of preprocessor definitions. The default is to compile GLEW into a DLL.

  3. Add opengl32.lib to the list of Additional Dependencies (under Linker/Inputs). This will resolve the missing wgl* symbols.

Alternatively, you might consider using the project files included under the build/vc12 subfolder of GLEW to build a static library and link with it or add the project glew_static into your solution. Steps 2 and 3 above would still be necessary.

BTW, every Windows API function is documented and the required libraries and headers are described. For example, the docs for wglGetCurrentDC() has a table with header, library and DLL that provide the function.

sterin
  • 1,898
  • 15
  • 13
  • So how do I do that? If I use a Windows API, can I still maintain cross-platform support? – FeeeshMeister Dec 27 '17 at 01:20
  • You need to add these as described at https://msdn.microsoft.com/en-us/library/ba1z7822.aspx – sterin Dec 27 '17 at 01:28
  • These are required by GLEW on Windows. On other platforms it has other requirements. It will not interfere cross-platform support - just every platform requires the appropriate libraries. – sterin Dec 27 '17 at 01:29
  • Stupid question: I have included both of the .lib files, but how do I include the .dll files? – FeeeshMeister Dec 27 '17 at 05:25
  • These .lib file are import libraries. When you link your code with an import library, it will automatically load the appropriate .DLL during runtime, if present. Fortunately, these two DLLs should be present on every windows machine and will automatically be loaded. See also https://en.wikipedia.org/wiki/Dynamic-link_library#Import_libraries – sterin Dec 27 '17 at 05:33
  • It still isn't working though. None of the errors have been resolved. – FeeeshMeister Dec 27 '17 at 05:36
  • @FeeeshMeister I've updated the answer. – sterin Dec 27 '17 at 07:18
  • Thank you. It is working perfectly now. For some reason opengl32.lib didn't exist on my on my computer, so I had to download it. – FeeeshMeister Dec 27 '17 at 19:38