Jump to content

  • Log In with Google      Sign In   
  • Create Account


Windows OpenGL project doesn't compile under release mode


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 SM ForeveR   Members   -  Reputation: 138

Like
0Likes
Like

Posted 11 October 2012 - 01:41 PM

Hi,
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:

C:\api\FMOD Programmers API Windows\api\inc;

C:\Program Files (x86)\FMOD SoundSystem\FMOD Programmers API Windows\api\inc;

C:\Binaries\DevIL-SDK-x86-1.7.8\include\IL;

C:\api\Glew\include\GL;

C:\api\DevIL\include\IL;$(IncludePath)

and these libraries:

C:\api\Glew\lib;

C:\api\DevIL\lib;

C:\api\FMOD Programmers API Windows\api\lib;

C:\Program Files (x86)\FMOD SoundSystem\FMOD Programmers API Windows\api\lib;

C:\Binaries\DevIL-SDK-x86-1.7.8\lib;$(LibraryPath)


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, 11 October 2012 - 01:43 PM.


Sponsor:

#2 mhagain   Crossbones+   -  Reputation: 6354

Like
1Likes
Like

Posted 11 October 2012 - 02:24 PM

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, 11 October 2012 - 02:26 PM.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#3 SM ForeveR   Members   -  Reputation: 138

Like
0Likes
Like

Posted 12 October 2012 - 05:51 AM

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:

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


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

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")

because they don't seem to do anything.

Edited by SM ForeveR, 12 October 2012 - 05:55 AM.


#4 mhagain   Crossbones+   -  Reputation: 6354

Like
1Likes
Like

Posted 12 October 2012 - 02:33 PM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#5 SM ForeveR   Members   -  Reputation: 138

Like
0Likes
Like

Posted 12 October 2012 - 11:17 PM

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?

LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library D:\Dropbox\Workspace\Visual Studio\GhostEngine\LINK GhostEngine


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, 13 October 2012 - 01:09 AM.


#6 SM ForeveR   Members   -  Reputation: 138

Like
0Likes
Like

Posted 27 October 2012 - 09:16 AM

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
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <WindowsX.h>
#define GLEW_STATIC
#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;
HDC	 hDC;
HGLRC   hRC;
#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()
{
    PIXELFORMATDESCRIPTOR pfd, *ppfd;
    int pixelformat;
    ppfd = &pfd;
    ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
    ppfd->nVersion = 1;
    ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    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);
    SetupPixelFormat();
    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
    SwapBuffers(hDC);
}
// Handle window events and messages
LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM  wParam, LPARAM  lParam)
{
    switch (uMsg) {
    case WM_MOUSEMOVE:
	    break;
    case WM_SIZE:
	    ResizeGraphics();
	    break;
    case WM_CLOSE:
	    DestroyWindow(hWnd);
	    break;

    case WM_DESTROY:
	    PostQuitMessage(0);
	    break;

    // Default event handler
    default:
	    return DefWindowProc (hWnd, uMsg, wParam, lParam);
	    break;
    }

    return 1;
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
#ifdef _DEBUG
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );
#endif
    const LPCWSTR appname = TEXT("Ghost engine");
    WNDCLASS wndclass;
    MSG	  msg;

    // Define the window class
    wndclass.style		 = 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(
		    appname,
		    appname,
		    WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
		    CW_USEDEFAULT,
		    CW_USEDEFAULT,
		    800,
		    600,
		    NULL,
		    NULL,
		    hInstance,
		    NULL);

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


#7 SM ForeveR   Members   -  Reputation: 138

Like
0Likes
Like

Posted 29 October 2012 - 04:56 AM

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, 29 October 2012 - 10:50 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS