Creating a dynamic library on Linux with DMD
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Sun Jun 10 16:56:18 PDT 2007
Frank Benoit wrote:
> I found that "nm -u libT.so" tells me about lots of unresolved symbols.
> They prevent the .so from loading in a non D app. I want to export only
> "extern(C)" functions.
(This assumes GDC)
You could try using visibility attributes. I've never needed them, but
AFAICT this should work on ELF targets and Darwin[1]:
Pass -fvisibility=hidden on the command line for all your modules
(including those in the standard library; you'll have to recompile this
unless you can figure out some way to apply them to the binary library).
This will hide all symbols from anything outside the shared lib they're
in, unless overridden for that specific symbol.
The way to do that should be to either use:
---
pragma(GNU_attribute, visibility("default")) {
// ... declarations of exported functions ...
// (The braces are optional if only one symbol is declared within)
}
---
or, for each function to be exported:
---
pragma(GNU_set_attribute, FUNCTION_NAME, visibility("default"));
---
References:
Command line: http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html
(at the bottom, -fvisibility)
Visibility attribute:
http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html#index-g_t_0040code_007bvisibility_007d-attribute-1980
GDC syntax for attributes: http://dgcc.sourceforge.net/gdc/manual.html
(section "Declaration and Type Attributes")
[1]: I have no idea if it'll work on Windows, but .so isn't typically
used there so that shouldn't matter :).
More information about the Digitalmars-d
mailing list