Bug 922 – export keyword causes undefined references on linux

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2007-02-02T13:08:00Z
Last change time
2017-01-16T23:24:50Z
Keywords
bootcamp
Assigned to
nobody
Creator
torhu

Comments

Comment #0 by torhu — 2007-02-02T13:08:49Z
Let's say you have a C lib that you want to link with your D app. You'd have a D 'header' like this: // need access to global_var defined in the C lib export extern extern (C) { int global_var; } The export keyword is there to facilitate dynamic linking on Windows. On linux, it causes link failure, both with static and dynamic linking. "undefined reference to `_imp__global_var'". This is not a actual error message, since I don't have access to a linux box. But similar errors have been reported by others. Supposedly, 'export' is not needed with ELF, as all symbols are visible by default. So I suppose dmd should ignore export on linux? The workaround we're using is to have a script remove 'export' from the files before compiling on linux. Pretty ugly. Littering code with version statements, or reorganizing it so we can put 'version (Windows) export:' somewhere wasn't very attractive either.
Comment #1 by thomas-dloop — 2007-04-05T11:38:43Z
(In reply to description) > Let's say you have a C lib that you want to link with your D app. You'd have a D 'header' like this: > > // need access to global_var defined in the C lib > export extern extern (C) { > int global_var; > } > > The export keyword is there to facilitate dynamic linking on Windows. > On linux, it causes link failure, both with static and dynamic linking. > "undefined reference to `_imp__global_var'". This is not a actual error > message, since I don't have access to a linux box. But similar errors have > been reported by others. Let's avoid any potential "extern" isssues: # # export int global_var; # # void main(){ printf("%X\n", global_var); # a.d:(.gnu.linkonce.t_Dmain+0x4): undefined reference to `_imp__D1a10global_vari' > Supposedly, 'export' is not needed with ELF, as all symbols are visible by default. > So I suppose dmd should ignore export on linux? DMD doesn't use ELF's visibility features, thus export isn't required under Linux. > The workaround we're using is to have a script remove 'export' from the files > before compiling on linux. Pretty ugly. Littering code with version statements, > or reorganizing it so we can put 'version (Windows) export:' somewhere wasn't > very attractive either. Another option would be to use the GDC compiler. Added to DStress as http://dstress.kuehne.cn/run/e/export_01_A.d
Comment #2 by code — 2013-04-06T18:39:18Z
Still happens, looks like the Windows mangling is applied to ELF.
Comment #3 by bugzilla — 2016-11-14T21:52:49Z
Comment #4 by github-bugzilla — 2016-11-15T07:14:18Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/fdde441cfd341ad573b3dc9b11e994ed55adfe68 Fix issue 922 - Don't mangle exported symbol names on linux. https://github.com/dlang/dmd/commit/0152061d082bc6ea86fd27df734a3d1d81e825d9 Merge pull request #6250 from LemonBoy/manglelin Fix issue 922 - Don't mangle exported symbol names on linux.
Comment #5 by github-bugzilla — 2016-12-27T14:41:02Z
Commits pushed to scope at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/fdde441cfd341ad573b3dc9b11e994ed55adfe68 Fix issue 922 - Don't mangle exported symbol names on linux. https://github.com/dlang/dmd/commit/0152061d082bc6ea86fd27df734a3d1d81e825d9 Merge pull request #6250 from LemonBoy/manglelin
Comment #6 by github-bugzilla — 2017-01-16T23:24:50Z
Commits pushed to newCTFE at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/fdde441cfd341ad573b3dc9b11e994ed55adfe68 Fix issue 922 - Don't mangle exported symbol names on linux. https://github.com/dlang/dmd/commit/0152061d082bc6ea86fd27df734a3d1d81e825d9 Merge pull request #6250 from LemonBoy/manglelin