Linking with gl3n can't find reference to _Dmodule_ref

"Nordlöw" per.nordlow at gmail.com
Sun Aug 25 03:12:46 PDT 2013


I'm starting a geometry module (fixed dimensional linear algebra) 
similar to Boost.Geometry.
I want these structures to have tight integration with OpenGL 
wrappers.
I've built and installed gl3n and thought it would be a good base 
to start with.

But when I try to link my sample application

#!/usr/bin/env rdmd

pragma(lib, "gl3n");

import gl3n.linalg;
import std.stdio;
import std.algorithm;

void main(string args[]) {
     writeln(vec2(2, 3).x);
     writeln(vec2(2, 3));
     writeln(cross(vec3(2, 3, 4),
                   vec3(4, 3, 2)));
     writeln(dot(vec3(2, 3, 4),
                 vec3(4, 3, 2)));
     writeln(vec3(2, 3, 4));
}

I get the linking error

/home/per/opt/x86_64-unknown-linux-gnu/dmd/bin/dmd -debug -gc 
-unittest -D 
-Dd/home/per/.emacs.d/auto-builds/dmd/Debug-Boundscheck-Unittest/home/per/Work/cognia/ 
-w  ~/Work/cognia/geometry.d 
-of/home/per/.emacs.d/auto-builds/dmd/Debug-Boundscheck-Unittest/home/per/Work/cognia/geometry
/home/per/opt/x86_64-unknown-linux-gnu/dmd/bin/../lib/libgl3n.a(util.o): 
In function `no symbol':
gl3n/util.d:(.text+0x6): undefined reference to `_Dmodule_ref'
/home/per/opt/x86_64-unknown-linux-gnu/dmd/bin/../lib/libgl3n.a(linalg.o): 
In function `no symbol':
gl3n/linalg.d:(.text+0x6): undefined reference to `_Dmodule_ref'
/home/per/opt/x86_64-unknown-linux-gnu/dmd/bin/../lib/libgl3n.a(plane.o): 
In function `no symbol':
gl3n/plane.d:(.text+0x6): undefined reference to `_Dmodule_ref'
/home/per/opt/x86_64-unknown-linux-gnu/dmd/bin/../lib/libgl3n.a(plane.o): 
In function 
`_D4gl3n5plane13__T6PlaneTTfZ6PlaneT8opEqualsMxFNaNbNfS4gl3n5plane13__T6PlaneTTfZ6PlaneTZb':
gl3n/plane.d:(.text._D4gl3n5plane13__T6PlaneTTfZ6PlaneT8opEqualsMxFNaNbNfS4gl3n5plane13__T6PlaneTTfZ6PlaneTZb+0x51): 
undefined reference to 
`_D4gl3n6linalg16__T6VectorTfVi3Z6Vector53__T8opEqualsTxS4gl3n6linalg16__T6VectorTfVi3Z6VectorZ8opEqualsMxFNaNbNfxS4gl3n6linalg16__T6VectorTfVi3Z6VectorZb'
/home/per/opt/x86_64-unknown-linux-gnu/dmd/bin/../lib/libgl3n.a(math.o): 
In function `no symbol':
gl3n/math.d:(.text+0x6): undefined reference to `_Dmodule_ref'
collect2: error: ld returned 1 exit status
--- errorlevel 1

I know DMD finds the libgl3n.a because otherwise it complains 
about hundreds of missing symbols.
It is however strange that a single gl3n-symbol is missing.
Maybe there's a bug gl3n.

I've tried adding

extern (C) void* _Dmodule_ref = null;

the line as indicated in other threads but then again I get

/home/per/opt/x86_64-unknown-linux-gnu/dmd/bin/dmd -debug -gc 
-unittest -D 
-Dd/home/per/.emacs.d/auto-builds/dmd/Debug-Boundscheck-Unittest/home/per/Work/cognia/ 
-w  ~/Work/cognia/geometry.d 
-of/home/per/.emacs.d/auto-builds/dmd/Debug-Boundscheck-Unittest/home/per/Work/cognia/geometry
/usr/bin/ld: _Dmodule_ref: TLS definition in 
/home/per/.emacs.d/auto-builds/dmd/Debug-Boundscheck-Unittest/home/per/Work/cognia/geometry.o 
section .tbss mismatches non-TLS reference in 
/home/per/opt/x86_64-unknown-linux-gnu/dmd/bin/../lib/libgl3n.a(util.o)
/home/per/opt/x86_64-unknown-linux-gnu/dmd/bin/../lib/libgl3n.a: 
could not read symbols: Bad value
collect2: error: ld returned 1 exit status
--- errorlevel 1

I can't understand what the meaning of _Dmodule_ref even not 
after having read about it in other threads.
Some say it has to do with linking to C libraries but gl3n 
doesn't use C libraries.

The error is removed when I remove

pragma(lib, "gl3n");

along with the import and uses gl3n structures (of course)

so the symbols _Dmodule_ref is referenced from libgl3n.a

What is wrong?

Thx,
Per Nordlöw


More information about the Digitalmars-d mailing list