5
votes

I can't link properly to glew.

I have done:

#define GLEW_STATIC
#include "glew/glew.h"
#pragma comment(lib, "glew/glew32s.lib")

However, I still get the error:

LNK2019: unresolved external symbol __glewGenBuffersARB referenced in function initialize

2
Are you building a 32 or 64 bit program, and are you using the correct corresponding glew32s.lib file?Mark
Maybe you should use <> brackets in the #include?Eitan T
It seems that the linker does not find the glew .lib file. Try checking that it is in the library search path.Tal Darom
@EitanT If that was the problem it would fail in compilation time. In this case the failure is in the linking time.Tal Darom
@Mark I am running on a 64 bit machine. I'm not sure how to rebuild glew to run on 64bit.MintGrowth

2 Answers

13
votes

Save yourself a lot of trouble and just put the glew.c file into your project. I never bother with linking to a glew library externally. Once you have that in there, the GLEW_STATIC macro will work. It's only one file, and (if this matters to you) it will carry nicely across platforms (rather than having to rebuild several OS-specific libs).

1
votes

I want to extend the excellent @TheBuzzSaw's idea by providing a more detailed answer for a cmake project.

  1. Download GLEW sources from here.
  2. Unzip the archive and copy two files (src/glew.c and include/GL/glew.h) into your project's directory.
  3. Edit glew.c so that the beginning of the file looks like this:
#ifndef GLEW_INCLUDE
#include "glew.h"  /* Point to local glew.h file. */
#else
#include GLEW_INCLUDE
#endif
  1. Use the following in your main.cpp file to include static GLEW correctly:
#define GLEW_STATIC
#include "glew.h"
  1. To build the project, you must compile and link the static GLEW library. Sample CMakeLists.txt file with the use of copied files:
cmake_minimum_required(VERSION 3.17)
project(your-project-name)

add_library(STATIC_GLEW glew.c)
add_executable(your-project-name main.cpp)


target_link_libraries(your-project-name STATIC_GLEW)

Now, you should be able to build your project without any linking errors 🎉