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:
[indent=1]C:\api\FMOD Programmers API Windows\api\inc;
[indent=1]C:\Program Files (x86)\FMOD SoundSystem\FMOD Programmers API Windows\api\inc;
[indent=1]C:\Binaries\DevIL-SDK-x86-1.7.8\include\IL;
[indent=1]C:\api\Glew\include\GL;
[indent=1]C:\api\DevIL\include\IL;$(IncludePath)
and these libraries:
[indent=1]C:\api\Glew\lib;
[indent=1]C:\api\DevIL\lib;
[indent=1]C:\api\FMOD Programmers API Windows\api\lib;
[indent=1]C:\Program Files (x86)\FMOD SoundSystem\FMOD Programmers API Windows\api\lib;
[indent=1]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.
Windows OpenGL project doesn't compile under release mode
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).
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).
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
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")
because they don't seem to do anything.
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
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")
because they don't seem to do anything.
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.
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
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.
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
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.
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?
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;
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement