beginner's linking error

James Cranch j.d.cranch at sheffield.ac.uk
Thu Jan 17 10:38:50 UTC 2019


Hi all,

I've just installed gdc from Debian Stable (gdc (Debian 
6.3.0-18+deb9u1) 6.3.0 20170516), and have been having linker 
errors when using writeln.

A minimal nonworking example is as follows: I have a file 
library.d which contains the following:

| module library;
|
| import std.stdio;
|
| class Greeter(string s) {
|
|   this() { }
|
|   void say_hello() {
|     writeln("Hello ", s, "!");
|   }
| }

I also have a file executable.d which contains the following:

| module executable;
| import library;
|
| int main() {
|
|   alias G = Greeter!("James");
|   G a = new G();
|   a.say_hello();
|   return 0;
| }

An attempt to compile it looks as follows:

| $ gdc executable.d -o executable
| /tmp/cc4RjTlb.o:(.data.rel+0x10): undefined reference to 
`_D7library12__ModuleInfoZ'
| collect2: error: ld returned 1 exit status

If I remove the import std.stdio and the writeln command from 
library.d, then it all works, so I'm clearly not linking 
libraries right, but it's not clear to me what to do.


More information about the Digitalmars-d-learn mailing list