I am developing hobby opengl3 engine and I decided to make a new .dll build of it. It uses GLEW to get opengl3 functions from GPU. I've successfully builded it about 5 months ago, but now I've changed a lot and it doesn't want to get working.
So the .dll builds perfectly (windows7, mingw).
I've made a simple program and it crashes on first call to glCreateProgram
which is runned by code from mylib.dll.
in pseudocode:
#include "mylib.hpp"
int main(){
std::cout << (void*)glCreateProgram << "\n";
// displays 0 as glCreateProgram haven't been loaded yet
myspace::Window* = new SDL2BasedWindow(...);
//this constructor is from my .dll and calls glewInit() which returns GLEW_OK
std::cout << (void*)glCreateProgram << "\n";
//this displays proper address
int testGLEW= glCreateProgram();
std::cout << "glCreateProgram from main: " << testGLEW<< "\n";
//this displays 1 which means valid call to glCreateProgram
window->runApplication(new Application(...));
//Application is user-defined class, it further creates myspace::ShaderProgram
//which is imported from my .dll (part of my engine) which then calls
//glCreateProgram in it's initialisation
//(it is first call to any function which should be initialized by GLEW if we count only code imported from mylib.dll)
}
//in ShaderProgram constructor:
std::cout << "trying to call glCreateProgram, address: ";
std::cout << (void*)glCreateProgram << "\n"; //this displays 0 (!)
int id = glCreateProgram(); //this ends execution with SIGSEGV
printf("created program: %d\n", id); //so this one is never called
So my question is, why GLEW works only in code which is not imported from my .dll and how can I fix it?
Btw I've checked nm mylib.dll
ant it contains glCreateProgram
and other glew dependent functions, I also use #define GLEW_STATIC
both in .dll and program that uses this .dll
Thanks for your help!