# DLL Problem

This topic is 4386 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Can DLLs loaded during runtime (using LoadLibrary or dlopen interfaces) use functions defined in the executable which loaded them? I'm having a problem with a GUI DLL for my music sequencer, which cannot be linked due to unresolved references:
main.o(.text+0xe):main.cpp: undefined reference to RegisterMainLoop'`
I guess this is a dumb question, but I'm quite new at DLLs. On the other hand, Assembler, C, C++, Scheme and Haskell code snippets occur frequently in my dreams... :)

##### Share on other sites
I'm not sure about on non-Win32, but on Win32, yes. You need to provide a prototype for the function so you don't get a compile error. If you make your exe export some symbols (with __declspec(dllexport)), then you'll get a .lib file generated, which you'll need to link with your DLL.

The other alternative is to export them as extern "C" __declspec(dllexport), and use GetProcAddress() (or dlsym() I think it is on Unix) to get the address of the function at runtime.

There's usually a cleaner way to do it though, such as calling a function in the DLL and passing it a function pointer (or a structure containing several function pointers) which the DLL can then use to call executable functions.

##### Share on other sites
I knew it was something as simple as dllexport! Silly me...
Thanks.

Umm, one more dumb question...
Can member functions be __declspec(dllexport)ed just like regular ones?

##### Share on other sites
Quote:
 Original post by phraineCan member functions be __declspec(dllexport)ed just like regular ones?
As far as I'm aware, you need to export an entire class. And you won't be able to use runtime linking to get the symbols (without a lot of hacking about), you'll have to link to the lib.

• 10
• 19
• 14
• 19
• 15