digitalmars.D.learn - Importing a module from another directory
- Derix (24/24) Dec 27 2014 I try to compile the basic HelloWorld.d example in which I only
- Adam D. Ruppe (8/11) Dec 27 2014 I don't know about the IDE, but the command line is easy: all
- Derix (6/6) Dec 27 2014 But of course ! I should have thought of this myself.
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (18/24) Dec 27 2014 The error comes from the linker, the compiler itself found your
- Derix (1/1) Dec 27 2014 OK thanks.
- Mike Parker (10/16) Dec 27 2014 -I is for compile time, not link time. When the compiler is compling a
- ketmar via Digitalmars-d-learn (7/22) Dec 27 2014 On Sat, 27 Dec 2014 17:38:55 +0000
- FrankLike (6/30) Dec 28 2014 If you use the dco,maybe it's ok:
- michaladdric (4/4) Dec 29 2014 I too new to this concept but I heard about the line command and
I try to compile the basic HelloWorld.d example in which I only added import Journal; where Journal is a module I defined in Journal.d in another directory. So I have /home/derix/development/publishing/journal/journal.d and /home/derix/development/examples/helloworld/main.d I work with MonoDevelop. In Project/Project Options/Includes I specified /home/derix/development/publishing/journal Building from MonoDevelop spews the following command line dmd -debug -gc "main.d" "-I/usr/include/dmd" "-I/home/derix/development/publishing/journal" "-odobj/Debug" "-of/home/derix/development/example/helloworld/bin/Debug/example" -w and the following error --- errorlevel 1 obj/Debug/example.o:(.data+0x78): undefined reference to `_D7Journal12__ModuleInfoZ' What am I missing ? Or, to put it more simply, what would be the correct dmd command line to import a module defined in a sibling directory ? Thanks,
Dec 27 2014
On Saturday, 27 December 2014 at 17:36:39 UTC, Derix wrote:What am I missing ? Or, to put it more simply, what would be the correct dmd command line to import a module defined in a sibling directory ?I don't know about the IDE, but the command line is easy: all your projects modules can be listed on it and it will work. dmd yourfile.d journal/journal.d giving them all at once means the necessary code will always be found, compiled, and linked in. It is also generally faster than trying to compile files separately, and easier too - an all around win.
Dec 27 2014
But of course ! I should have thought of this myself. Subsequent question though : what is the -I option for ? The dmd embedded help states -Ipath where to look for imports so I'd naively think it would work too, but it yields the same error as above.
Dec 27 2014
On Saturday, 27 December 2014 at 18:01:19 UTC, Derix wrote:But of course ! I should have thought of this myself. Subsequent question though : what is the -I option for ? The dmd embedded help states -Ipath where to look for imports so I'd naively think it would work too, but it yields the same error as above.The error comes from the linker, the compiler itself found your imported module and compiled it without error. In general, there are two ways in which you can compile a larger project consisting of multiple files. Either compile everything at once, as Adam suggests. In this case, the compiler will also call the linker for you to put all parts together and produce an executable. The other way would be to compile each file (module) separately. To do so, you have to specify the `-c` option; the compiler will then write out an object file for the module you specified on the command line. When you're done compiling all modules, you need to invoke the linker manually, specifying all of the object files. The latter is the default model used in C and C++. The reason is that during development it is often faster to recompile only those parts of your project that have actually changed (and those that depend on them). Compiling D however, is a lot faster than compiling C++, therefore the first method is usually preferrable.
Dec 27 2014
On 12/28/2014 3:01 AM, Derix wrote:But of course ! I should have thought of this myself. Subsequent question though : what is the -I option for ? The dmd embedded help states -Ipath where to look for imports so I'd naively think it would work too, but it yields the same error as above.-I is for compile time, not link time. When the compiler is compling a module, the compiler searches the import path for all the imported modules, loads the files and parses them. This is how it knows which symbols are available in the module it is currently compiling. The compiler does not automatically compile imported modules, so the -I switch has no impact on the linker. Any modules you actually import and use still need to be passed for linking in some manner, either by compiling all the modules at the same time, compiling each individually with -c, linking with a library, or linking with individual object files.
Dec 27 2014
On Sat, 27 Dec 2014 17:38:55 +0000 "Adam D. Ruppe via Digitalmars-d-learn" <digitalmars-d-learn puremagic.com> wrote:On Saturday, 27 December 2014 at 17:36:39 UTC, Derix wrote:and not always working too. ;-) there is at least one bug with template function attributes inferencing, but as i found no volunteers to narrow it down and i'm using only separate compilation, it will wait for another reporter. ;-)What am I missing ? Or, to put it more simply, what would be the correct dmd command line to import a module defined in a sibling directory ?=20 I don't know about the IDE, but the command line is easy: all=20 your projects modules can be listed on it and it will work. =20 dmd yourfile.d journal/journal.d =20 =20 giving them all at once means the necessary code will always be=20 found, compiled, and linked in. It is also generally faster than=20 trying to compile files separately, and easier too - an all=20 around win.
Dec 27 2014
On Saturday, 27 December 2014 at 17:36:39 UTC, Derix wrote:I try to compile the basic HelloWorld.d example in which I only added import Journal; where Journal is a module I defined in Journal.d in another directory. So I have /home/derix/development/publishing/journal/journal.d and /home/derix/development/examples/helloworld/main.d I work with MonoDevelop. In Project/Project Options/Includes I specified /home/derix/development/publishing/journal Building from MonoDevelop spews the following command line dmd -debug -gc "main.d" "-I/usr/include/dmd" "-I/home/derix/development/publishing/journal" "-odobj/Debug" "-of/home/derix/development/example/helloworld/bin/Debug/example" -w and the following error --- errorlevel 1 obj/Debug/example.o:(.data+0x78): undefined reference to `_D7Journal12__ModuleInfoZ' What am I missing ? Or, to put it more simply, what would be the correct dmd command line to import a module defined in a sibling directory ? Thanks,If you use the dco,maybe it's ok: at /home/derix/development dco https://github.com/FrankLIKE/dco/ Frank
Dec 28 2014
I too new to this concept but I heard about the line command and it is easy to learn and implement it. [url=http://www.redchipsolutions.com/]Lectora elearning development[/url]
Dec 29 2014