Sign in to follow this  

OpenGL Windows OpenGL project doesn't compile under release mode

This topic is 1905 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this strange problem, which I've ignored for quite some time...
I develop in debug mode, which works fine. But whenever I switch to release mode the following part of my code
[source lang="cpp"] GLenum err = glewInit();
if (err != GLEW_OK) LOGI("GLEW not initialized.");
if (!GLEW_VERSION_2_1) LOGI("GLEW doesn't support OpenGL 2.1");[/source]
produces this message:
INFO: GLEW doesn't support OpenGL 2.1

I have this line in my header (glew.h is between <>):
[source lang="cpp"]#include glew.h
#pragma comment(lib, "glew32.lib")[/source]
I include these directories:
[indent=1]C:\api\FMOD Programmers API Windows\api\inc;[/indent]
[indent=1]C:\Program Files (x86)\FMOD SoundSystem\FMOD Programmers API Windows\api\inc;[/indent]
and these libraries:
[indent=1]C:\api\FMOD Programmers API Windows\api\lib;[/indent]
[indent=1]C:\Program Files (x86)\FMOD SoundSystem\FMOD Programmers API Windows\api\lib;[/indent]

I've had copied debug include and library entries to release mode, so they should be the same.

Any ideas, why in release mode glew doesn't add support for OpenGL2.1?
Thanks, Martin. Edited by SM ForeveR

Share this post

Link to post
Share on other sites
Just did a release build and got GL4.2 OK.

I'm linking statically to GLEW (#define GLEW_STATIC before including glew.h, and using "glew32s.lib") and I think that the hint is in that.

I suspect that because you're linking dynamically you may have an outdated glew32.dll somewhere on your system that the release build is picking up but the debug build is not, possibly on account of different output directories for each.

If not, it's also possible that you may have a Mesa version of opengl32.dll somewhere in the path used by the release build - that's also limited to older GL_VERSIONS (it would be a slightly older version of Mesa too as I'm fairly certain that current supports 2.1). Edited by mhagain

Share this post

Link to post
Share on other sites
Thanks for reply. So I tried a few options.
1.) I replaced my include code to this one (instead of "GL/glew.h" I use<GL/glew.h>, this markup script has some issues.):

[source lang="cpp"]#define GLEW_STATIC
#include "GL/glew.h"
#pragma comment(lib, "glew32s.lib")[/source]

This is what error I get now:
[indent=1]Error 3 error LNK1169: one or more multiply defined symbols found D:\Dropbox\Workspace\Visual Studio\GhostEngine\Release\GhostEngine.exe 1 1 GhostEngine
Error 2 error LNK2005: _glewInit@0 already defined in glew32.lib(glew32.dll) D:\Dropbox\Workspace\Visual Studio\GhostEngine\glew32s.lib(glew.obj) GhostEngine
Warning 1 warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library D:\Dropbox\Workspace\Visual Studio\GhostEngine\LINK GhostEngine[/indent]

2) I downloaded latest glew binaries and changed my glew32.dll found in system and system32 folders with new one.
Unfortunately it didn't helped.
3) I tried including source files into my project, but it also spilled loads of error messages about missing functions or something.

I have latest nvidia drivers for 670GTX. Can this be the cause?
I also don't include following lines
[indent=1]#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")[/indent]
because they don't seem to do anything. Edited by SM ForeveR

Share this post

Link to post
Share on other sites
Is your "#pragma comment(lib" in a .h file or a .c/.cpp file? If you put it in a .h file then it will be included multiple times and you will get a multiply defined error - that's normal and expected behaviour. It's sufficient to just put in a .c/.cpp file as the project only needs to link to it once; I normally pick the file where I have my GL context creation code, but it really doesn't matter which, that's just from the perspective of keeping related things in the same place.

Share this post

Link to post
Share on other sites
They were indeed in .h file, but the file had include guards and even trying this didn't changed anything, but your post gave me an idea, on what is wrong, so I went into linker->additional dependencies and what I found was glew32.lib which was causing the error, after removing it I can compile again in debug and release. But unfortunately the problem still persist, in release mode I get the same error with GLEW_STATIC defined.

Does the following warning might have anything to do with this?
[indent=1]LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library D:\Dropbox\Workspace\Visual Studio\GhostEngine\LINK GhostEngine[/indent]

EDIT: just tried to create new project on different machine and older visual studio 2010 compiler. Same thing happens there.

EDIT2: even tried moving released mode binary to yet another different PC, and even there the problem persists. Probably has nothing to do with PC's graphic cards drivers. Edited by SM ForeveR

Share this post

Link to post
Share on other sites
I still can't seem to find any way to make working release version.
Could someone please try this code on visual studio and tell me if release version works for them without any errors?
#ifdef _DEBUG
#include <stdlib.h>
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW

#include <windows.h>
#include <WindowsX.h>
#include <glew.h>
#pragma comment(lib, "glew32s.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#include <string>
#include <vector>
#include <set>
#include <hash_map>
#include <sstream>
#include <stdio.h>
#include <fstream>
#include <iostream>
HWND hWnd;
#define LOGI(...) { char buff[10240]; sprintf_s(buff, __VA_ARGS__); OutputDebugStringA("INFO: "); OutputDebugStringA(buff); OutputDebugStringA("\n"); }
#define LOGW(...) { char buff[10240]; sprintf_s(buff, __VA_ARGS__); OutputDebugStringA("WARNING: "); OutputDebugStringA(buff); OutputDebugStringA("\n"); }
#define LOGE(...) { char buff[10240]; sprintf_s(buff, __VA_ARGS__); MessageBoxA(0, buff, "Error", MB_ICONERROR); \
OutputDebugStringA("ERROR: "); OutputDebugStringA(buff); OutputDebugStringA("\n"); }
// Set up pixel format for graphics initialization
void SetupPixelFormat()
int pixelformat;
ppfd = &pfd;
ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
ppfd->nVersion = 1;
ppfd->dwLayerMask = PFD_MAIN_PLANE;
ppfd->iPixelType = PFD_TYPE_COLORINDEX;
ppfd->cColorBits = 16;
ppfd->cDepthBits = 24;
ppfd->cAccumBits = 0;
ppfd->cStencilBits = 0;
pixelformat = ChoosePixelFormat(hDC, ppfd);
SetPixelFormat(hDC, pixelformat, ppfd);
// Initialize OpenGL graphics
bool InitGraphics()
hDC = GetDC(hWnd);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
GLenum err = glewInit();
if (err != GLEW_OK) {
LOGE("GLEW not initialized.");
return false;
if (!GLEW_VERSION_2_1) {
LOGE("GLEW doesn't support OpenGL 2.1");
return false;
return true;
// Resize graphics to fit window
void ResizeGraphics()
// Get new window size
RECT rect;
GetClientRect(hWnd, &rect);
int width = rect.right;
int height = rect.bottom;
// Draw frame
void DrawGraphics()
// Show the new scene
// Handle window events and messages
LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
switch (uMsg) {
case WM_SIZE:
case WM_CLOSE:


// Default event handler
return DefWindowProc (hWnd, uMsg, wParam, lParam);

return 1;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
#ifdef _DEBUG
const LPCWSTR appname = TEXT("Ghost engine");
WNDCLASS wndclass;
MSG msg;

// Define the window class = 0;
wndclass.lpfnWndProc = (WNDPROC)MainWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, appname);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wndclass.lpszMenuName = appname;
wndclass.lpszClassName = appname;
//wndclass.hIcon = static_cast<HICON>(LoadImage(hInstance, MAKEINTRESOURCE(IDI_ERROR), IMAGE_ICON, 32, 32, LR_DEFAULTSIZE));

// Register the window class
if (!RegisterClass(&wndclass)) {
LOGE("Failed to register window struct.");
return FALSE;

// Create the window
hWnd = CreateWindow(

if (!hWnd) {
LOGE("Failed to initialize window.");
return false;
// Initialize OpenGL
if (!InitGraphics()) {
LOGI("Deleting engine.");
ReleaseDC(hWnd, hDC);
// Display the window
ShowWindow(hWnd, nCmdShow);
// Event loop
while (true)
if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE)
if (!GetMessage(&msg, NULL, 0, 0)) break;
LOGI("Deleting engine.");
ReleaseDC(hWnd, hDC);
return 1;

Share this post

Link to post
Share on other sites
ppfd->iPixelType must be PFD_TYPE_RGBA in release mode, but not in debug, which is so messed up I can't even begin to describe how furious I was finding this out after long hours of trial and errors... Edited by SM ForeveR

Share this post

Link to post
Share on other sites

This topic is 1905 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By xhcao
      Does sync be needed to read texture content after access texture image in compute shader?
      My simple code is as below,
      glBindImageTexture(0, texture[0], 0, GL_FALSE, 3, GL_READ_ONLY, GL_R32UI);
      glBindImageTexture(1, texture[1], 0, GL_FALSE, 4, GL_WRITE_ONLY, GL_R32UI);
      glDispatchCompute(1, 1, 1);
      // Does sync be needed here?
      glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
                                     GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, texture[1], 0);
      glReadPixels(0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT, outputValues);
      Compute shader is very simple, imageLoad content from texture[0], and imageStore content to texture[1]. Does need to sync after dispatchCompute?
    • By Jonathan2006
      My question: is it possible to transform multiple angular velocities so that they can be reinserted as one? My research is below:
      // This works quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); quat quaternion2 = GEMultiplyQuaternions(quaternion1, GEQuaternionFromAngleRadians(angleRadiansVector2)); quat quaternion3 = GEMultiplyQuaternions(quaternion2, GEQuaternionFromAngleRadians(angleRadiansVector3)); glMultMatrixf(GEMat4FromQuaternion(quaternion3).array); // The first two work fine but not the third. Why? quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); vec3 vector1 = GETransformQuaternionAndVector(quaternion1, angularVelocity1); quat quaternion2 = GEQuaternionFromAngleRadians(angleRadiansVector2); vec3 vector2 = GETransformQuaternionAndVector(quaternion2, angularVelocity2); // This doesn't work //quat quaternion3 = GEQuaternionFromAngleRadians(angleRadiansVector3); //vec3 vector3 = GETransformQuaternionAndVector(quaternion3, angularVelocity3); vec3 angleVelocity = GEAddVectors(vector1, vector2); // Does not work: vec3 angleVelocity = GEAddVectors(vector1, GEAddVectors(vector2, vector3)); static vec3 angleRadiansVector; vec3 angularAcceleration = GESetVector(0.0, 0.0, 0.0); // Sending it through one angular velocity later in my motion engine angleVelocity = GEAddVectors(angleVelocity, GEMultiplyVectorAndScalar(angularAcceleration, timeStep)); angleRadiansVector = GEAddVectors(angleRadiansVector, GEMultiplyVectorAndScalar(angleVelocity, timeStep)); glMultMatrixf(GEMat4FromEulerAngle(angleRadiansVector).array); Also how do I combine multiple angularAcceleration variables? Is there an easier way to transform the angular values?
    • By dpadam450
      I have this code below in both my vertex and fragment shader, however when I request glGetUniformLocation("Lights[0].diffuse") or "Lights[0].attenuation", it returns -1. It will only give me a valid uniform location if I actually use the diffuse/attenuation variables in the VERTEX shader. Because I use position in the vertex shader, it always returns a valid uniform location. I've read that I can share uniforms across both vertex and fragment, but I'm confused what this is even compiling to if this is the case.
      #define NUM_LIGHTS 2
      struct Light
          vec3 position;
          vec3 diffuse;
          float attenuation;
      uniform Light Lights[NUM_LIGHTS];
    • By pr033r
      I have a Bachelor project on topic "Implenet 3D Boid's algorithm in OpenGL". All OpenGL issues works fine for me, all rendering etc. But when I started implement the boid's algorithm it was getting worse and worse. I read article ( inspirate from another code (here: but it still doesn't work like in tutorials and videos. For example the main problem: when I apply Cohesion (one of three main laws of boids) it makes some "cycling knot". Second, when some flock touch to another it scary change the coordination or respawn in origin (x: 0, y:0. z:0). Just some streng things. 
      I followed many tutorials, change a try everything but it isn't so smooth, without lags like in another videos. I really need your help. 
      My code (optimalizing branch):
      Exe file (if you want to look) and models folder (for those who will download the sources):
      Thanks for any help...

    • By Andrija
      I am currently trying to implement shadow mapping into my project , but although i can render my depth map to the screen and it looks okay , when i sample it with shadowCoords there is no shadow.
      Here is my light space matrix calculation
      mat4x4 lightViewMatrix; vec3 sun_pos = {SUN_OFFSET * the_sun->direction[0], SUN_OFFSET * the_sun->direction[1], SUN_OFFSET * the_sun->direction[2]}; mat4x4_look_at(lightViewMatrix,sun_pos,player->pos,up); mat4x4_mul(lightSpaceMatrix,lightProjMatrix,lightViewMatrix); I will tweak the values for the size and frustum of the shadow map, but for now i just want to draw shadows around the player position
      the_sun->direction is a normalized vector so i multiply it by a constant to get the position.
      player->pos is the camera position in world space
      the light projection matrix is calculated like this:
      mat4x4_ortho(lightProjMatrix,-SHADOW_FAR,SHADOW_FAR,-SHADOW_FAR,SHADOW_FAR,NEAR,SHADOW_FAR); Shadow vertex shader:
      uniform mat4 light_space_matrix; void main() { gl_Position = light_space_matrix * transfMatrix * vec4(position, 1.0f); } Shadow fragment shader:
      out float fragDepth; void main() { fragDepth = gl_FragCoord.z; } I am using deferred rendering so i have all my world positions in the g_positions buffer
      My shadow calculation in the deferred fragment shader:
      float get_shadow_fac(vec4 light_space_pos) { vec3 shadow_coords = / light_space_pos.w; shadow_coords = shadow_coords * 0.5 + 0.5; float closest_depth = texture(shadow_map, shadow_coords.xy).r; float current_depth = shadow_coords.z; float shadow_fac = 1.0; if(closest_depth < current_depth) shadow_fac = 0.5; return shadow_fac; } I call the function like this:
      get_shadow_fac(light_space_matrix * vec4(position,1.0)); Where position is the value i got from sampling the g_position buffer
      Here is my depth texture (i know it will produce low quality shadows but i just want to get it working for now):
      sorry because of the compression , the black smudges are trees ...
      EDIT: Depth texture attachment:
  • Popular Now