| June 04, 2005boxer linking difficulties | ||||
|---|---|---|---|---|
| 
 | ||||
| I'm having trouble using std.boxer in code compiled into a lib. I've
recompiled phobos with all the debugging info I could and it was still
giving a link error not finding an unbox instantiation. The following two
files give an example
boxt.d:
import boxt2;
int main() {
  double x = foo!(double)(10);
  printf("%g\n",x);
  return 0;
}
boxt2.d:
module boxt2;
import std.boxer;
template foo(T) {
  T foo(int x){ return unbox!(T)(box(x)); }
}
This works fine if you compile like
  dmd boxt.d boxt2.d
but it fails to link if you do
  dmd -c boxt2.d
  dmd boxt.d boxt2.obj
With MinTL I'm using boxes to do implicit numeric conversions but since
MinTL is a library I compile everything down to objs and stuff them in a
lib. Hence I found the simplest thing for me to do is insert some dead code
into the code using MinTL to explicitly instatiate the right unbox function.
eg
boxt.d:
import boxt2;
import boxer;
int main() {
  unbox!(double)(box(10)); // dead code to get the template instantiated
  double x = foo!(double)(10);
  printf("%g\n",x);
  return 0;
}
I vaguely remember some discussions about instantiating templates across obj
files but I don't remember what the upshot was.
 | ||||
| June 04, 2005Re: boxer linking difficulties | ||||
|---|---|---|---|---|
| 
 | ||||
| Posted in reply to Ben Hinkle | Ben, I have same problems with boxer. Have not fixed them. "Solution" - I am not assembling lib from objs at all. AFAIR - problem is exactly the same as with any template in debug mode. Librarian just don't like them. Andrew. "Ben Hinkle" <ben.hinkle@gmail.com> wrote in message news:d7r7kb$1rnj$1@digitaldaemon.com... > I'm having trouble using std.boxer in code compiled into a lib. I've > recompiled phobos with all the debugging info I could and it was still > giving a link error not finding an unbox instantiation. The following two > files give an example > boxt.d: > import boxt2; > int main() { > double x = foo!(double)(10); > printf("%g\n",x); > return 0; > } > > boxt2.d: > module boxt2; > import std.boxer; > template foo(T) { > T foo(int x){ return unbox!(T)(box(x)); } > } > > This works fine if you compile like > dmd boxt.d boxt2.d > but it fails to link if you do > dmd -c boxt2.d > dmd boxt.d boxt2.obj > With MinTL I'm using boxes to do implicit numeric conversions but since > MinTL is a library I compile everything down to objs and stuff them in a > lib. Hence I found the simplest thing for me to do is insert some dead > code into the code using MinTL to explicitly instatiate the right unbox > function. eg > boxt.d: > import boxt2; > import boxer; > int main() { > unbox!(double)(box(10)); // dead code to get the template instantiated > double x = foo!(double)(10); > printf("%g\n",x); > return 0; > } > I vaguely remember some discussions about instantiating templates across > obj files but I don't remember what the upshot was. > | |||
Copyright © 1999-2021 by the D Language Foundation
  Permalink
Permalink Reply
Reply