Skip to content

[Branch: openmath] Use MicroTeX as a static library ? #130

@jokteur

Description

@jokteur

Hello again,

I will probably post a few issues as I am discovering how to use this library. I managed to solve #127 by following the examples. It compiles with MSVC and Imgui. I did a quick implementation of graphic_imgui.h and graphic_imgui.cpp.

For now, I have the following problem: as I implement graphic_imgui, which will be exported to a shared library (dll with MSVC), it is impossible to use static variables in the original GUI library. I will make an example to be clearer.

Lets say that loading a font needs a static variable (to check if the application is initialized):

MyGUILibrary::LoadFont(...) {
    // Check app initialization
    if (!App::app_state) { // Calls a static variable
        // Do stuff
    }
}

Now when implementing graphic_imgui, if I do the following:

Font_imgui::Font_imgui(const std::string& file, float size) {
    MyGUILibrary::LoadFont(...);
}

there will be a problem. Indeed, as Font_imgui::Font_imgui symbol will be in the shared library (lets call it microtex-imgui), as soon as this dll will be loaded, the static variable App::app_state will be reinitialized, even if it was correctly initialized in the main thread of the application before the dll was loaded (this is exactly what happens when I test MicroTeX with my dll microtex-imgui).

I do know that static variables are evil, and extern variables even more so. But it may happen that the GUI library uses some internal static variables that may be used when loading fonts or other things. I feel like (when following the examples) that MicroTeX forces me to create a shared library where I need to create an interface within this library that interacts with the rest of the project. It also possible that I missunderstood how to use correctly this project.

I see here three workarounds:

  1. Use MicroTeX as a static library, such that the interface graphic_xxx does not need to be loaded at runtime. My question would be: how to do this ? I tried to change the CMakeLists.txt in lib/ but failed miserably.
  2. Implement the interface graphic_xxx in an abstract way, such that it don't directly makes calls to the GUI library.
  3. Rework completly the GUI library such that it may never ever use static variables -> I don't see this as a viable solution.

I thank you in advance for your answers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions