Skip to content

Commit

Permalink
LDC: Use -fvisibility=public -dllimport=all when compiling a Window…
Browse files Browse the repository at this point in the history
…s DLL

As `-shared` can only be used when linking the DLL in the same cmdline too.
On Windows, `-shared` changes the defaults of some important settings wrt.
dllim/export, so specify those explicitly when *compiling* a DLL with dub
(or some static lib dependency thereof etc.).
  • Loading branch information
kinke committed Aug 19, 2022
1 parent 6c35542 commit 15cfddc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 13 additions & 2 deletions source/dub/compilers/ldc.d
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,19 @@ config /etc/ldc2.conf (x86_64-pc-linux-gnu)
settings.lflags = null;
}

if (settings.options & BuildOption.pic)
settings.addDFlags("-relocation-model=pic");
if (settings.options & BuildOption.pic) {
if (platform.isWindows()) {
/* This has nothing to do with PIC, but as the PIC option is exclusively
* set internally for code that ends up in a dynamic library, explicitly
* specify what `-shared` defaults to (`-shared` can't be used when
* compiling only, without linking).
* *Pre*pending the flags enables the user to override them.
*/
settings.prependDFlags("-fvisibility=public", "-dllimport=all");
} else {
settings.addDFlags("-relocation-model=pic");
}
}

assert(fields & BuildSetting.dflags);
assert(fields & BuildSetting.copyFiles);
Expand Down
3 changes: 1 addition & 2 deletions test/1-dynLib-simple/dub.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"name": "dynlib-simple",
"targetType": "dynamicLibrary",
"dflags-ldc": ["-link-defaultlib-shared", "--fvisibility=public"]
"targetType": "dynamicLibrary"
}

0 comments on commit 15cfddc

Please sign in to comment.