# Possible Dynamic Library Bug

**URL:** <https://forum.juce.com/t/possible-dynamic-library-bug/37055>\
**Category:** General JUCE discussion\
**Created:** [January 10, 2020, 1:25pm UTC](https://forum.juce.com/t/possible-dynamic-library-bug/37055 "2020-01-10T13:25:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ComposerShield](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/composershield/32/6655_2.png) [@ComposerShield](https://forum.juce.com/u/ComposerShield)\
**Post date:** [January 10, 2020, 1:25pm UTC](https://forum.juce.com/t/possible-dynamic-library-bug/37055/1 "2020-01-10T13:25:01Z")

</div>

Hey guys,

I wanted to share an issue I ran into. I made a version of a project into a dynamic library build to include inside another project. Everything worked except a DocumentWindow I was using in the project. I then compiled the project as a static library and included it that way to test and the DocumentWindow worked just fine.

Basically, when built as a dynamic library, I can interact with the DocumentWindow, calling a bunch of functions on it like setting the top left corner position and such, with no crashes jasserts, complaining or anything. I just don’t see the window.

Working on a Mac using the tip of the development branch updated from a few weeks ago.

---

<div class="post-metadata">

**Author:** ![ed95](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ed95/32/7635_2.png) [@ed95](https://forum.juce.com/u/ed95)\
**Post date:** [January 22, 2020, 12:40pm UTC](https://forum.juce.com/t/possible-dynamic-library-bug/37055/2 "2020-01-22T12:40:12Z")

</div>

Can you reproduce this with a simple example? I’ve built a JUCE `.dylib` on macOS with a single .cpp file containing the following:

```auto
#include <JuceHeader.h>

extern "C" JUCE_API void JUCE_CALLTYPE openWindow()
{
    ScopedJuceInitialiser_GUI gui;
    
    struct Window : public DocumentWindow
    {
        Window()
             : DocumentWindow ({}, Colours::hotpink, DocumentWindow::allButtons)
        {
            setUsingNativeTitleBar (true);
            setResizable (true, true);
            centreWithSize (500, 500);
            
            setVisible (true);
        }
    };
    
    Window w;
    Process::setDockIconVisible (true);
    MessageManager::getInstance()->runDispatchLoop();
}

```

Then I’m loading the library and calling `openWindow` from a simple console app:

```auto
int main (int argc, char* argv[])
{
    DynamicLibrary lib ("DllTest.dylib");
    jassert (lib.getNativeHandle() != nullptr);
    
    auto* fPtr = reinterpret_cast<void(*)()> (lib.getFunction ("openWindow"));
    jassert (fPtr != nullptr);
   
    if (fPtr != nullptr)
        fPtr();
    
    return 0;
}

```

And everything is working as expected.

---

<div class="post-metadata">

**Author:** ![fiedleraudio](https://avatars.discourse-cdn.com/v4/letter/f/5daacb/32.png) [@fiedleraudio](https://forum.juce.com/u/fiedleraudio)\
**Post date:** [October 26, 2024, 4:10pm UTC](https://forum.juce.com/t/possible-dynamic-library-bug/37055/3 "2024-10-26T16:10:39Z")

</div>

Old thread, but i was looking how to get this to work. This example is not working. lib.getFunction (“openWindow”) returns NULL. Any idea why?

---

<div class="post-metadata">

**Author:** ![fiedleraudio](https://avatars.discourse-cdn.com/v4/letter/f/5daacb/32.png) [@fiedleraudio](https://forum.juce.com/u/fiedleraudio)\
**Post date:** [October 26, 2024, 6:28pm UTC](https://forum.juce.com/t/possible-dynamic-library-bug/37055/4 "2024-10-26T18:28:53Z")

</div>

found the answer. Only one .h is not sufficient. One cpp file needs to be present, even if it is empty. Then the .h file will actually be compiled.
