Accessing anything GLEW related immediately crashe

2019-04-13 04:04发布

Here is the code:

#define GLEW_STATIC
#include "GL/glew.h"

int main () {
    glewExperimental = GL_TRUE;
    return 0;
}

Here is the output:

Process finished with exit code -1073741515 (0xC0000135)

When the 'glewExperimental' line is commented out, program exits with 0.

Here is the CMake file (I am using CLion):

cmake_minimum_required(VERSION 2.8.4)
project(untitled)

add_definitions(-DGL_GLEXT_PROTOTYPES)
add_definitions(-DWINVER=0x0602)
add_definitions(-D_WIN32_WINNT=0x0602)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(untitled ${SOURCE_FILES})

target_link_libraries(untitled  glfw3  glew32 opengl32 gdi32)

I am using MinGW toolchain on Windows 8.1.

I compiled the GLEW library with the following bat file:

gcc -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.o -c src/glew.c

gcc -shared -Wl,-soname,libglew32.dll -Wl,--out-implib,lib/libglew32.dll.a -o lib/glew32.dll src/glew.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32

ar cr lib/libglew32.a src/glew.o

I placed the resulting libglew32.a, libglew32.dll.a in MinGW/lib folder.

I placed teh glew32.dll in Windows/System32 folder.

I placed the GL/glew.h, glxew.h, wglew.h in the MinGW/include folder.

What am I missing?

I cannot figure out why simply assigning a value to that variable throws an exception...

2条回答
疯言疯语
2楼-- · 2019-04-13 04:43

I was able to resolve by adding the following line to CMakeLists.txt

add_definitions(-DGLEW_STATIC)

I do not understand why the above would work since, to my understanding the following would have had the same affect:

#define GLEW_STATIC
查看更多
Emotional °昔
3楼-- · 2019-04-13 04:48

As I understood there are two questions to answer:

Why does my program crash when I include glewExperimental = GL_TRUE; but not when leaving it away?

Your program crashes because it cannot load the glew library. When you leave this line away, no call to glew is made and the program will most likely not even load it.

Why does my program not find glew32.dll although I copied it into the system32 folder?

If you have a 64-bit operating system, than system32 is the folder where the 64-bit dlls are placed. I know this sounds sic!, but that's how windows works. 32-bit libraries are located in SysWOW64. This SO-answer contains more details about this: why-do-64-bit-dlls-go-to-system32-and-32-bit-dlls-to-syswow64-on-64-bit-windows.

In general you should never place dlls somewhere in the windows folder. This folders are reserved for system libraries/system-wide libraries like drivers etc. The reason for this is, that you get into deep troubles if someone else copies another version of e.g. glew32.dll into the system folder, which will most probably crash you app. The best way to place your own libraries is in the directory your executable lies in.

查看更多
登录 后发表回答