www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Compiling with -unittest on a c wrapper

reply simendsjo <simendsjo gmail.com> writes:
Given the header file mymodule.h:
void f(void);

I'm creating mymodule.d:
extern(C) void f();

It works fine when compiling with this library, but when I compile with  
-unittest, I get undefined reference to ModuleInfo:
sample.o:(.data+0x210): undefined reference to  
`_D7mylibrary7mymodule12__ModuleInfoZ'

What am I doing wrong?

I saw the following snippet in deimos/openssl:
// Very boiled down version because we cannot use std.traits without  
causing
// DMD to create a ModuleInfo reference for _d_util, which would require  
users
// to include the Deimos files in the build.
template ExternC(T) if (is(typeof(*(T.init)) P == function)) {
	static if (is(typeof(*(T.init)) R == return)) {
		static if (is(typeof(*(T.init)) P == function)) {
			alias extern(C) R function(P) ExternC;
		}
	}
}

.. but I'm not sure if this relates to my problem..
Feb 24 2012
parent simendsjo <simendsjo gmail.com> writes:
On Fri, 24 Feb 2012 10:06:33 +0100, simendsjo <simendsjo gmail.com> wrote:

 Given the header file mymodule.h:
 void f(void);

 I'm creating mymodule.d:
 extern(C) void f();

 It works fine when compiling with this library, but when I compile with  
 -unittest, I get undefined reference to ModuleInfo:
 sample.o:(.data+0x210): undefined reference to  
 `_D7mylibrary7mymodule12__ModuleInfoZ'

 What am I doing wrong?

 I saw the following snippet in deimos/openssl:
 // Very boiled down version because we cannot use std.traits without  
 causing
 // DMD to create a ModuleInfo reference for _d_util, which would require  
 users
 // to include the Deimos files in the build.
 template ExternC(T) if (is(typeof(*(T.init)) P == function)) {
 	static if (is(typeof(*(T.init)) R == return)) {
 		static if (is(typeof(*(T.init)) P == function)) {
 			alias extern(C) R function(P) ExternC;
 		}
 	}
 }

 .. but I'm not sure if this relates to my problem..
Hmm. If I add all the wrapper modules, I'm able to compile.. Guess it's related. What's the best way to handle this?
Feb 24 2012