D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11439 - Linker error while importing modules in unit test blocks
Summary: Linker error while importing modules in unit test blocks
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Mac OS X
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-04 10:34 UTC by Gary Willoughby
Modified: 2024-12-13 18:13 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Gary Willoughby 2013-11-04 10:34:51 UTC
The test case involves three files: test/methods.d, test/test1.d and test/test2.d. Because this is describing a problem with importing the files need to reside inside a directory, here i've called it 'test'.

Source code:

test/methods.d:

	module test.methods;

	import std.array;

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

test/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());
	}

test/test2.d:

	module test.test2;

	import test.test1;

	struct T
	{
		int x[];
	}

I compile the above sources like this:

	rdmd --force -de -debug -I~/<dir containing test dir> -m64 -main -property -unittest -w methods.d
	rdmd --force -de -debug -I~/<dir containing test dir> -m64 -main -property -unittest -w test1.d
	rdmd --force -de -debug -I~/<dir containing test dir> -m64 -main -property -unittest -w test2.d

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 compiles fine but it shouldn't be needed:

	unittest
	{
		import test.methods;
	}
Comment 1 or 2016-01-02 11:32:47 UTC
Anyone has any idea about this one? I experience something similar
Comment 2 dlangBugzillaToGithub 2024-12-13 18:13:38 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18707

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB