error LNK2019: unresolved external symbol

I was having the same problem. Finally found useful instructions in this Visual Studio and OpenGL tutorial. The issue was correctly including the .dll files for the right configuration (Win32 or x64).


This is definitely a problem with linker settings, specifically to do with the glew library. Why your previous attempts to fix it have not worked isnt too clear to me.

Are you able to get any tutorial programs that glew provides to compile?


Edit

From your comment it looks like you are having issues including your lib file.
- Can you verify if it is where you think it is (is it installed correctly)?
- Does Visual studio know where it is supposed to be(is correct path to lib provided)?

Does Project ->Right click + properties -> Configuration Properties -> Linker -> General -> Additional Linker directories in Visual Studio have the path to the folder containing glew32.lib?


I got the glew binaries from http://glew.sourceforge.net/index.html (https://sourceforge.net/projects/glew/files/glew/1.9.0/glew-1.9.0-win32.zip/download) and freeglut 2.8.0 MSVC Package from http://www.transmissionzero.co.uk/software/freeglut-devel/ (http://files.transmissionzero.co.uk/software/development/GLUT/freeglut-MSVC.zip)

I set the include path to glew-1.9.0\include\, freeglut\include\ and library path to freeglut\lib\, glew-1.9.0\lib\.

I corrected the header of your file as

#include <Windows.h>
#include <iostream>
#include <gl/glew.h>
#include <gl/GL.h>
#include <gl/freeglut.h>

#pragma comment(lib, "glew32.lib")

Linking successful, and it worked.

UPD

When using third-party libraries, usually:

  • You must set the include path to <3rdPartyDir>\include, but not to <3rdPartyDir>\include\lib_name. Declare its inclusion in the source code should be:

correct: #include <lib_name/header_name.h>

wrong: #include <header_name.h>, because within the library can be internal dependencies, for example #include <lib_name/other_header_name.h>

  • Set the library path to <3rdPartyDir>\lib. Then, you must specify the required libraries, one of the following methods:

For MSVC, add

#ifdef _MSC_VER
#pragma comment(lib, "lib1_name.lib")
#pragma comment(lib, "lib2_name.lib")
/// etc
#endif

Or, add the required libraries to the linker options.

Some libraries support auto-linking mechanism (for example, freeglut), that is, the header file contains a line like #pragma comment(lib, "lib1_name.lib")

  • Copy the required dlls from <3rdPartyDir>\bin to <MyExePath>\