'glfwInit needs to be called twice for shared libraries, why would that be?
Experimenting around I found something interesting let's say we have A.cpp and B.cpp A.cpp in pseudocode is something like this:
// Load library
void (*InitializeRendering)(GLFWwindow*);
InitializeRendering = (decltype(InitializeRendering)) dlsym(renderer_handle, INIT_RENDERING_FUNC);
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
auto window = glfwCreateWindow(800, 800, "Vulkan window", nullptr, nullptr);
InitializeRendering(window);
And then B.cpp
extern "C"
{
void InitializeRendering(GLFWwindow* window)
{
glfwInit();
// Init vulkan surface from window
}
This setup works, what's interesting is, if you delete the call to glfwInit() inside B.cpp things won't work anymore, you very much need to have it initialized in the shared library object. I am wondering why this would be the case? It seems that the global state between the 2 binaries is not shared.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
