On Wednesday, 20 November 2013 at 02:14:29 UTC, Carlos wrote:
But I want to declare this functions "print" outside of the
file and call the file to be loaded by the compiler. So I can
use the same solution in various program without having to copy
paste it to each one.
first way - put this "print" function into its own module,
compile your "client" program simply adding print module in
source list.
example: "dmd yourmain.d print.d"
(this way you actually just adding all code from "print" module
to your program)
second way(phobos actually using this) - put your "print" in its
own module and compile it as static library. then when compiling
your client program link with this lib and add import search path
with -I to location where print can be found.
example: "dmd print.d -lib && dmd yourmain.d print.lib"
(with this way only used stuff gets imported(function/types/etc.
definitions), and then linked at compile time with static lib
which contains actual compiled code for that function).