digitalmars.D - Compile fails, don't know why
- Nafees (54/54) Mar 18 2016 I tried to create a separate module for storing classes in, this
- Nafees (3/8) Mar 18 2016 Plus, the code works if the class is in the same module, and I
- Mathias Lang (7/16) Mar 18 2016 See the compilation command:
- Nafees (3/20) Mar 18 2016 Now I created a folder in the usr/include/dmd named qlib and
- Mathias Lang (11/33) Mar 18 2016 Just realized this was in the wrong forum. Please move your
- Mike Parker (18/20) Mar 18 2016 You have a fundamental misunderstanding here. Imported modules
I tried to create a separate module for storing classes in, this is the new module <code> module qlib.classes; //QLib.Classes class tstrlist{ private: string[] list; uint taken; public: string read(uint index){ return list[index]; } void set(uint index, string str){ if (index>=list.length){ list[index]=str; } } void add(string str){ list.length++; list[list.length-1]=str; } } </code> and the project's code <code> module main; //import std.stdio; import qlib.classes; void main(){ tstrlist slst = new tstrlist(); //slst.add("str1"); //readln; } </code> And this is what I get after compile: <code> Building: LrnD (Release) Performing main compilation... Current dictionary: /home/nafees/Desktop/Projects/LrnD/LrnD dmd -O -release "main.d" "-I/usr/include/dmd" "-I/home/nafees/Desktop/Projects/DLibrary" "-odobj/Release" "-of/home/nafees/Desktop/Projects/LrnD/LrnD/bin/Release/LrnD" -w -vcolumns obj/Release/LrnD.o: In function `_Dmain': main.d:(.text._Dmain+0x9): undefined reference to `_D4qlib7classes8tstrlist7__ClassZ' collect2: error: ld returned 1 exit status --- errorlevel 1 Exit code 1 Build complete -- 1 error, 0 warnings ---------------------- Done ---------------------- Build: 1 error, 0 warnings </code>
Mar 18 2016
On Friday, 18 March 2016 at 10:07:18 UTC, Nafees wrote:I tried to create a separate module for storing classes in, this is the new module <code> module qlib.classes; [...]Plus, the code works if the class is in the same module, and I did add the path to the QLib.classes module in the compiler.
Mar 18 2016
On Friday, 18 March 2016 at 10:11:50 UTC, Nafees wrote:On Friday, 18 March 2016 at 10:07:18 UTC, Nafees wrote:See the compilation command: dmd -O -release "main.d" "-I/usr/include/dmd" "-I/home/nafees/Desktop/Projects/DLibrary" "-odobj/Release" "-of/home/nafees/Desktop/Projects/LrnD/LrnD/bin/Release/LrnD" -w -vcolumns Here your module is not linked in, only main.dI tried to create a separate module for storing classes in, this is the new module <code> module qlib.classes; [...]Plus, the code works if the class is in the same module, and I did add the path to the QLib.classes module in the compiler.
Mar 18 2016
On Friday, 18 March 2016 at 10:25:06 UTC, Mathias Lang wrote:On Friday, 18 March 2016 at 10:11:50 UTC, Nafees wrote:Now I created a folder in the usr/include/dmd named qlib and placed the module there, yet it won't work.On Friday, 18 March 2016 at 10:07:18 UTC, Nafees wrote:See the compilation command: dmd -O -release "main.d" "-I/usr/include/dmd" "-I/home/nafees/Desktop/Projects/DLibrary" "-odobj/Release" "-of/home/nafees/Desktop/Projects/LrnD/LrnD/bin/Release/LrnD" -w -vcolumns Here your module is not linked in, only main.dI tried to create a separate module for storing classes in, this is the new module <code> module qlib.classes; [...]Plus, the code works if the class is in the same module, and I did add the path to the QLib.classes module in the compiler.
Mar 18 2016
On Friday, 18 March 2016 at 10:38:00 UTC, Nafees wrote:On Friday, 18 March 2016 at 10:25:06 UTC, Mathias Lang wrote:Just realized this was in the wrong forum. Please move your question to learn (http://forum.dlang.org/group/learn), as General is intended for general-purpose discussion. You might want to provide additional informations, like which build tool you are using. The problem is not where the module lives (the compiler would complain if it couldn't find it), but that you didn't ask for the module to be part of your executable. To do so, you need to add `path/to/qlib/classes.d` to your command line.On Friday, 18 March 2016 at 10:11:50 UTC, Nafees wrote:Now I created a folder in the usr/include/dmd named qlib and placed the module there, yet it won't work.On Friday, 18 March 2016 at 10:07:18 UTC, Nafees wrote:See the compilation command: dmd -O -release "main.d" "-I/usr/include/dmd" "-I/home/nafees/Desktop/Projects/DLibrary" "-odobj/Release" "-of/home/nafees/Desktop/Projects/LrnD/LrnD/bin/Release/LrnD" -w -vcolumns Here your module is not linked in, only main.dI tried to create a separate module for storing classes in, this is the new module <code> module qlib.classes; [...]Plus, the code works if the class is in the same module, and I did add the path to the QLib.classes module in the compiler.
Mar 18 2016
On Friday, 18 March 2016 at 10:38:00 UTC, Nafees wrote:Now I created a folder in the usr/include/dmd named qlib and placed the module there, yet it won't work.You have a fundamental misunderstanding here. Imported modules are not automatically compiled when you add them to the import path with -I. Imported modules still need to be compiled and linked into the program. You can do this in one of three ways: 1) Pass the imported module on the command line as advised above. In that case, it doesn't need to be on the import path with -I, since the compiler already has the relevant module on the command line. 2) Compile the module separately and pass the compiled object on the command line with the other source. In that case you still need to use -I to tell the compiler where to look for imported symbols. 3) Compile the module separately and add it with one or more objects to a static library. Still need -I here. -I is just so the compiler knows where to look for imported modules so that it knows which symbols are available. It does not cause those modules to be compiled.
Mar 18 2016