Jump to page: 1 2
Thread overview
How to use classes from another d files
Oct 22, 2019
Vinod K Chandran
Oct 22, 2019
Adam D. Ruppe
Oct 22, 2019
Vinod K Chandran
Oct 22, 2019
Ali Çehreli
Oct 24, 2019
Vinod K Chandran
Oct 22, 2019
Daniel Kozak
Oct 24, 2019
Vinod K Chandran
Oct 24, 2019
Vinod K Chandran
Oct 22, 2019
Vinod K Chandran
Oct 22, 2019
Adam D. Ruppe
Oct 24, 2019
Vinod K Chandran
October 22, 2019
Hi all,
I am new to D. But some fair experience with vb.net. I was playing with D classes.  I wrote a class in a D file.
The file name is "classFile.d"
```D
class TestClass {

    int myIntVar        ;
    string myStringVar  ;

    this(int miv, string msv) {
        this.myIntVar = miv     ;
        this.myStringVar = msv  ;
    }//End this

}//End Class
```
And i wrote my main function in another file named "caller.d". Both these files are in same folder.
```D
import std.stdio ;

void main() {
    import classFile ;


    TestClass tc = new TestClass(37, "Sample String") ;
    writeln(tc.myStringVar) ;
    tc.myIntVar = 45 ;
    writeln(tc.myIntVar)  ;

    writeln("its over..") ;

}//End main
```
This is the error message i got.
;------------------------------------------------
caller.obj(caller)
 Error 42: Symbol Undefined __D9classFile9TestClass6__ctorMFiAyaZCQBjQBc
caller.obj(caller)
 Error 42: Symbol Undefined __D9classFile9TestClass7__ClassZ
Error: linker exited with status 2
PS E:\OneDrive Folder\OneDrive\Programming\D Programming\Samples\Sample2>



October 22, 2019
On Tuesday, 22 October 2019 at 17:34:51 UTC, Vinod K Chandran wrote:
> Hi all,
> I am new to D. But some fair experience with vb.net. I was playing with D classes.  I wrote a class in a D file.
> The file name is "classFile.d"

did you compile with dmd -i or list both files on the dmd command line?
October 22, 2019
On Tuesday, 22 October 2019 at 17:34:51 UTC, Vinod K Chandran wrote:
> Hi all,
> I am new to D. But some fair experience with vb.net. I was playing with D classes.  I wrote a class in a D file.
> The file name is "classFile.d"
> ```D
> class TestClass {
>
> [...]

What you are seeing is a linker error. Build it as follows:

dmd caller.d classFile.d

Unrelated, first line of classFile.d needs be `module classFile`
October 22, 2019
On Tuesday, 22 October 2019 at 17:40:11 UTC, Arun Chandrasekaran wrote:
> On Tuesday, 22 October 2019 at 17:34:51 UTC, Vinod K Chandran wrote:
>> Hi all,
>> I am new to D. But some fair experience with vb.net. I was playing with D classes.  I wrote a class in a D file.
>> The file name is "classFile.d"
>> ```D
>> class TestClass {
>>
>> [...]
>
> What you are seeing is a linker error. Build it as follows:
>
> dmd caller.d classFile.d
>
> Unrelated, first line of classFile.d needs be `module classFile`

Thanks a lot. But what if there is too many include files ? Say, i have 10 files to import in main file, Do i need to type all the file names in cmd ?
Is there any dedicated ide in order to avoid this typing task ? I have tested it with Codeblocks, but didn't worked.
October 22, 2019
On Tuesday, 22 October 2019 at 17:38:58 UTC, Adam D. Ruppe wrote:
> On Tuesday, 22 October 2019 at 17:34:51 UTC, Vinod K Chandran wrote:
>> Hi all,
>> I am new to D. But some fair experience with vb.net. I was playing with D classes.  I wrote a class in a D file.
>> The file name is "classFile.d"
>
> did you compile with dmd -i or list both files on the dmd command line?

Thanks for the reply. Nope. I just typed this code in VS Code and hit the run button. Thats all. i think this cmd business will be difficult for me.
October 22, 2019
On Tuesday, 22 October 2019 at 18:21:36 UTC, Vinod K Chandran wrote:
> But what if there is too many include files ?

The dmd -i thing will do that for you

dmd -i main.d

and it will automatically find the others, assuming they are laid out so the module/import name matches the file name
October 22, 2019
On 10/22/2019 11:25 AM, Vinod K Chandran wrote:
> On Tuesday, 22 October 2019 at 17:38:58 UTC, Adam D. Ruppe wrote:
>> On Tuesday, 22 October 2019 at 17:34:51 UTC, Vinod K Chandran wrote:
>>> Hi all,
>>> I am new to D. But some fair experience with vb.net. I was playing
>>> with D classes.  I wrote a class in a D file.
>>> The file name is "classFile.d"
>>
>> did you compile with dmd -i or list both files on the dmd command line?

That: The -i switch is the answer to your question in the other post ("what if there is too many include files").

> Thanks for the reply. Nope. I just typed this code in VS Code and hit
> the run button. Thats all.

But not sufficient. :) IDEs like VS Code have a way of describing what your project involves. You need to add the two files to you "project". (I don't know the details for your IDE.)

> i think this cmd business will be difficult
> for me.

Yes, IDEs make it convenient.

Ali

October 22, 2019
On Tue, Oct 22, 2019 at 8:30 PM Vinod K Chandran via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote:
>
> On Tuesday, 22 October 2019 at 17:38:58 UTC, Adam D. Ruppe wrote:
> > On Tuesday, 22 October 2019 at 17:34:51 UTC, Vinod K Chandran wrote:
> >> Hi all,
> >> I am new to D. But some fair experience with vb.net. I was
> >> playing with D classes.  I wrote a class in a D file.
> >> The file name is "classFile.d"
> >
> > did you compile with dmd -i or list both files on the dmd command line?
>
> Thanks for the reply. Nope. I just typed this code in VS Code and hit the run button. Thats all. i think this cmd business will be difficult for me.

You should use dub. You will probably need it anyway in the future.

VS Code have nice plugins to work with D
you can install D Language utility extension pack
October 24, 2019
On Tuesday, 22 October 2019 at 18:31:17 UTC, Adam D. Ruppe wrote:
> On Tuesday, 22 October 2019 at 18:21:36 UTC, Vinod K Chandran wrote:
>> But what if there is too many include files ?
>
> The dmd -i thing will do that for you
>
> dmd -i main.d
>
> and it will automatically find the others, assuming they are laid out so the module/import name matches the file name

@Adam D. Ruppe,
Thanks. It worked. :)
October 24, 2019
On Tuesday, 22 October 2019 at 18:33:32 UTC, Ali Çehreli wrote:
> On 10/22/2019 11:25 AM, Vinod K Chandran wrote:
> > On Tuesday, 22 October 2019 at 17:38:58 UTC, Adam D. Ruppe
> wrote:
> >> [...]
> Chandran wrote:
> >>> [...]
> playing
> >> [...]
> command line?
>
> That: The -i switch is the answer to your question in the other post ("what if there is too many include files").
>
> > Thanks for the reply. Nope. I just typed this code in VS Code
> and hit
> > the run button. Thats all.
>
> But not sufficient. :) IDEs like VS Code have a way of describing what your project involves. You need to add the two files to you "project". (I don't know the details for your IDE.)
>
> > i think this cmd business will be difficult
> > for me.
>
> Yes, IDEs make it convenient.
>
> Ali

@Ali Çehreli,
Thanks for the detailed reply. I have tested with "dmd -i" and it worked.
« First   ‹ Prev
1 2