I am writing an executable file that uses dlopen () (LoadLibrary () on Windows) to dynamically load a shared library. The shared library uses characters from an executable file.
On Windows, this is possible. Executable files can export symbols: declspec (dllexport) and .def files work. The compiler, when creating the .exe, also creates the .lib file (the "import library"), so the DLL just needs to be associated with this .lib.
On Linux, this is possible. I pass -Wl, -export_dynamic when creating the executable so that it exports its characters.
On Mac OS X instead ... -Wl -export_dynamic does not work, but there is -Wl, -exported_symbols_list, <filename> , where <filename> is a list of exported characters (something like a simpler version of the .def file). But then creating a shared library is not so simple: the linker complains about unresolved characters.
I tried to hack: renamed the executable to lib <executable> .dylib and, linking the shared library, I passed -l <executable> . But it gives the error "cannot communicate with the main executable file."
A common problem is that there may be unresolved characters in shared Linux libraries, while Windows and Mac OS X do not allow this. But Windows has “import libraries” for resolving characters against dependencies, and Mac OS X does not seem to ...
How can this be solved on Mac OS X? Is there an equivalent to an “import library” (a stub library created by the Windows linker when creating the .dll, so if any module should dynamically reference the .dll, is it associated with the “import library”)? Or some other solution?
linker ld macos shared
user377486
source share