www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Linker error

reply "RenatoUtsch" <renatoutsch gmail.com> writes:
Hello,

I was trying to play with modules and import, but I couldn't 
understand why this code is giving linker errors:

/classy/widget.d
--------------------
module classy.widget;

class ReturnItself
{
	public ref ReturnItself returnItself()
	{
		return this;
	}

	public int returnNumber(in int number)
	{
		return number;
	}
}
--------------------

/testReturn.d
--------------------
import std.stdio, std.conv, classy.widget;

void main()
{
	auto returnItself = new ReturnItself;
	int number = 13;

	writeln(to!string(returnItself.returnItself()
						.returnItself()
						.returnItself()
						.returnItself()
						.returnNumber(number)));
}
--------------------

The linker error is the following:
--------------------
$ dmd testReturn.d
testReturn.o: In function `_Dmain':
testReturn.d:(.text._Dmain+0xa): undefined reference to 
`_D6classy6widget12ReturnItself7__ClassZ'
collect2: error: ld returned 1 exit status
--- errorlevel 1
$
--------------------

I am using Fedora 17, x86_64.


I will be grateful for all help I can get.
Nov 30 2012
next sibling parent "Maxim Fomin" <maxim maxim-fomin.ru> writes:
On Friday, 30 November 2012 at 18:44:31 UTC, RenatoUtsch wrote:
 <skipped>
 $ dmd testReturn.d
 ...

because you didn't compiled the second file.
Nov 30 2012
prev sibling parent "RenatoUtsch" <renatoutsch gmail.com> writes:
On Friday, 30 November 2012 at 19:09:12 UTC, Maxim Fomin wrote:
 On Friday, 30 November 2012 at 18:44:31 UTC, RenatoUtsch wrote:
 <skipped>
 $ dmd testReturn.d
 ...

because you didn't compiled the second file.

Man, I was going to say that it didn't work, that I tested it before, but then I noticed that I added classy.widget.d to the command line, not classy/widget.d, it worked. Sorry for the dumb mistake.
Nov 30 2012