digitalmars.D.learn - single class in file
- Jan Hanselaer (22/22) May 05 2007 Hi
- Bill Baxter (4/31) May 05 2007 Use 'dmd -c' if you want to compile only with no linking.
- Derek Parnell (38/45) May 05 2007 Ok, here is one way you can do that ...
- Jan Hanselaer (3/49) May 05 2007 That's the information I needed. Thanks a lot!
Hi I'm trying to make a class in a module. A bit inspired by java where one class is one object. Altough I tought this would work in D too. The code here works. But I just want the class Test in that file. And then I want to use it in my main program (in another file). I don't need a main in this module, but without it I can't compile the file. Whu is this? And what's the right way to do it? I can't just put all my code in one file. Well I could ... but I don't want to. file : test.d class Test { char[] name; int nr; this() { name = "test"; nr = 1; } } void main(){}
May 05 2007
Jan Hanselaer wrote:Hi I'm trying to make a class in a module. A bit inspired by java where one class is one object. Altough I tought this would work in D too. The code here works. But I just want the class Test in that file. And then I want to use it in my main program (in another file). I don't need a main in this module, but without it I can't compile the file. Whu is this? And what's the right way to do it? I can't just put all my code in one file. Well I could ... but I don't want to. file : test.d class Test { char[] name; int nr; this() { name = "test"; nr = 1; } } void main(){}Use 'dmd -c' if you want to compile only with no linking. Use bud or rebuild if you want to make your life easy. --bb
May 05 2007
On Sat, 5 May 2007 22:11:03 +0200, Jan Hanselaer wrote:Hi I'm trying to make a class in a module. A bit inspired by java where one class is one object. Altough I tought this would work in D too. The code here works. But I just want the class Test in that file. And then I want to use it in my main program (in another file).Ok, here is one way you can do that ... // file : test.d class Test { char[] name; int nr; this() { name = "test"; nr = 1; } } // ------- EOF -------- // file: app.d import test; void main(){} // ------- EOF -------- Then at the command line ... dmd app test Or if you want to do it in steps ... dmd test -c dmd app test.obj Or use one of the 'build' tools (eg. rebuild or bud) ... bud app The D compiler needs to have a 'main' routine to be able to link the file together. If you want to compile a file that does not have a main routine, you need to use the "-c" -switch, which stands for 'compile only; no linking'. And once you have all your files separately compiled, you need to link the application, so you supply the source file that contains the 'main' routine plus all the object files it needs on the command line. The 'build' tools help automate the compilation steps required. -- Derek Parnell Melbourne, Australia "Justice for David Hicks!" skype: derek.j.parnell
May 05 2007
"Derek Parnell" <derek psych.ward> schreef in bericht news:1vzymj9lmr9rr.1m84406w2ct0f$.dlg 40tude.net...On Sat, 5 May 2007 22:11:03 +0200, Jan Hanselaer wrote:That's the information I needed. Thanks a lot!Hi I'm trying to make a class in a module. A bit inspired by java where one class is one object. Altough I tought this would work in D too. The code here works. But I just want the class Test in that file. And then I want to use it in my main program (in another file).Ok, here is one way you can do that ... // file : test.d class Test { char[] name; int nr; this() { name = "test"; nr = 1; } } // ------- EOF -------- // file: app.d import test; void main(){} // ------- EOF -------- Then at the command line ... dmd app test Or if you want to do it in steps ... dmd test -c dmd app test.obj Or use one of the 'build' tools (eg. rebuild or bud) ... bud app The D compiler needs to have a 'main' routine to be able to link the file together. If you want to compile a file that does not have a main routine, you need to use the "-c" -switch, which stands for 'compile only; no linking'. And once you have all your files separately compiled, you need to link the application, so you supply the source file that contains the 'main' routine plus all the object files it needs on the command line. The 'build' tools help automate the compilation steps required. -- Derek Parnell Melbourne, Australia "Justice for David Hicks!" skype: derek.j.parnell
May 05 2007