Linker error regarding importing and unit tests. Is this a bug?

Gary Willoughby dev at nomad.so
Fri Nov 1 05:59:23 PDT 2013


I have a small test case that displays a linker error. I wondered 
if this is an issue with the tool chain or whether i'm doing 
something wrong.

I have a simple directory structure like this:

test/methods.d
test/test1.d
test/test2.d

Here is the source code for the above modules:

methods.d:

	module test.methods;

	import std.array;

	public bool nothing(int[] x)
	{
		return x.empty();
	}

test1.d:

	module test.test1;

	struct S
	{
		int x[];
	}

	unittest
	{
		import test.methods;
		import std.stdio;

		writeln("test1 unit test");

		S s;

		assert(s.x.nothing());
	}

test2.d:

	module test.test2;

	import test.test1;

	struct T
	{
		int x[];
	}

I compile the following sources like this:

	rdmd --force -de -debug -I~/Desktop -m64 -main -property 
-unittest -w <file>

Where <file> is an individual file above. I do this because i 
like to compile and tests each module in isolation running the 
unit tests. When i try and compile `test2.d` i get the following 
error:

Undefined symbols for architecture x86_64:
   "_D4test7methods12__ModuleInfoZ", referenced from:
       _D4test5test112__ModuleInfoZ in test2.o
   "_D4test7methods7nothingFAiZb", referenced from:
       _D4test5test114__unittestL8_1FZv in test2.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to 
see invocation)

If i add the following to the bottom of `test2.d` it all compiles 
fine:

	unittest
	{
		import test.methods;
	}

Any idea what's going on here?


More information about the Digitalmars-d-learn mailing list