Multiple glfw instances on main thread/process?

Hello, I am new to GLFW and C++ so I suspect my issue is more of a library usage issue than a problem with GLFW but I want to know why this is happening.

In the application I am writing I initialize glfw then call the glfw create window call. The glfw init is in one method I call from main, the glfw window create is called within the constructor of a custom window object created within custom application object member method.

I know glfw initialization works. The problem is that once I enter my application object it seems to have its own instance of the glfw global variables, so my window creation fails since it gets back a glfw not initialized error. This is still all call via main, and I am not trying to do any multithreading at this time. When the member method of my application object returns I see that the glfw global variables are once again initialized.

What is odd, is that if I copy and paste all of my code from my various files into a single cpp, it works. I suspect something is happening at compile time where it thinks my custom application object needs its own instance of the glfw library global variables even though it is on the same thread and process as main.

Any ideas on why this is happening? Is this a C++ library behavior or is something odd happening with GLFW?

Hi @Vixnil, welcome to the GLFW forum!

It is certainly possible to call glfwInit() from a function in one source file, and glfwCreateWindow from another.

Without seeing your code and how it’s being built it’s difficult to help with any diagnosis. Off the top of my head the only situation where I can imagine this happening is if you build your code with the create window being called from a library, and with GLFW being statically linked to both that library and your executable. If this is the case, then compiling and linking GLFW as a shared library (DLL in Windows terms) would help resolve this issue.

Hey @Vixnil ,

Not sure why you’re having trouble. I tried to recreate what you described, and it compiled and executed fine. As @dougbinks stated, you more than likely have some wonky linking happening.

Example Source Code