Thread overview
[Issue 922] New: export keyword causes undefined references on linux
Feb 02, 2007
d-bugmail
Apr 05, 2007
d-bugmail
Apr 07, 2013
Martin Nowak
February 02, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=922

           Summary: export keyword causes undefined references on linux
           Product: D
           Version: 1.00
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: link-failure
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: torhu@yahoo.com


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.


-- 

April 05, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=922





------- Comment #1 from thomas-dloop@kuehne.cn  2007-04-05 11:38 -------
(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


-- 

April 07, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=922


Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@dawg.eu


--- Comment #2 from Martin Nowak <code@dawg.eu> 2013-04-06 18:39:18 PDT ---
Still happens, looks like the Windows mangling is applied to ELF.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------