digitalmars.D.learn - separate and/or independent compilation
- Tibi (2/2) Jun 07 2007 Can someone please tell me a few words about separate compilation in D. ...
- Myron Alexander (20/23) Jun 07 2007 Tibi,
- Jarrett Billingsley (6/10) Jun 07 2007 Not exactly. When you import a module, it will only ever look for a sou...
- Myron Alexander (8/23) Jun 07 2007 Thanks for the clarification, I misunderstood how modules work.
- Jarrett Billingsley (3/7) Jun 07 2007 Right :)
- Myron Alexander (1/1) Jun 08 2007 Thanks
- BCS (10/17) Jun 07 2007 to compile a file and not link it use -c
Can someone please tell me a few words about separate compilation in D. A small example would be nice, if I`m not asking too much. And one more thing, I haven`t understood very well what import does, is it similar to the #include statement from C++ or is it somewhat different?
Jun 07 2007
Tibi wrote:Can someone please tell me a few words about separate compilation in D. A small example would be nice, if I`m not asking too much. And one more thing, I haven`t understood very well what import does, is it similar to the #include statement from C++ or is it somewhat different?Tibi, The import statement is more similar to Python (or Java) than to C/C++. The #include statement instructs the c/c++ pre-processor to include source into the current source file which is why you have to be careful about what you put in the included file and also why you should have guards. In D, the import statement imports a compiled module, not source. Modules are actually similar to classes in that they have constructors, destructors, public and private elements, and they provide a namespace. Their purpose is to provide functionality that the application can use, whether this is module globals, functions, classes, structs, type definitions, template definitions etc. In a module, you do not separate the declaration from the implementation, your implementation is the declaration. Modules are a phenomenal tool for library writers, and they also provide a great way to break up an application into functional units. In one sentence, modules provide the functionality of #include (and so much more) but with "special" binaries rather than source. Regards, Myron.
Jun 07 2007
"Myron Alexander" <someone somewhere.com> wrote in message news:f49mt6$1t6d$1 digitalmars.com...In D, the import statement imports a compiled module, not source. ... In one sentence, modules provide the functionality of #include (and so much more) but with "special" binaries rather than source.Not exactly. When you import a module, it will only ever look for a source file (.d or .di). It never looks for compiled modules. Once it finds a source file, it will lex it, parse it, and do enough semantic analysis to extract the symbol table, which can then be used from the current module.
Jun 07 2007
Jarrett Billingsley wrote:"Myron Alexander" <someone somewhere.com> wrote in message news:f49mt6$1t6d$1 digitalmars.com...Thanks for the clarification, I misunderstood how modules work. Please correct me if the following is incorrect: Modules are not included in the current source as part of the source (like #include does) but the module (.d) or module interface (.di) is parsed for declarations and module constructor/destructor/static methods. Thanks, Myron.In D, the import statement imports a compiled module, not source. ... In one sentence, modules provide the functionality of #include (and so much more) but with "special" binaries rather than source.Not exactly. When you import a module, it will only ever look for a source file (.d or .di). It never looks for compiled modules. Once it finds a source file, it will lex it, parse it, and do enough semantic analysis to extract the symbol table, which can then be used from the current module.
Jun 07 2007
"Myron Alexander" <someone somewhere.com> wrote in message news:f4a78d$qhk$1 digitalmars.com...Please correct me if the following is incorrect: Modules are not included in the current source as part of the source (like #include does) but the module (.d) or module interface (.di) is parsed for declarations and module constructor/destructor/static methods.Right :)
Jun 07 2007
Reply to Tibi,Can someone please tell me a few words about separate compilation in D. A small example would be nice, if I`m not asking too much. And one more thing, I haven`t understood very well what import does, is it similar to the #include statement from C++ or is it somewhat different?to compile a file and not link it use -c dmd -c myfile.d to link several object files uses your linker on linux gcc a.o b.o c.d -<needed flags> // the flags can be found by calling dmd with a hello world and watching the output to stdout on win32 it is about the same but the linker you will need to use in in dm/bin/link.exe and I don't remember how to get the args. OTOH if you call DMD with only object files, in win32 or linux it will link them
Jun 07 2007