Re: Dub version

2019-08-08 Thread Andre Pany via Digitalmars-d-learn

On Friday, 9 August 2019 at 01:36:43 UTC, greatsam4sure wrote:

On Friday, 9 August 2019 at 01:18:12 UTC, Elronnd wrote:

Dub add is not supported in dub 1.11.0


Use 'dub fetch'.




dub fetch dub
Fetching dub 1.16.0...
Please note that you need to use `dub run ` or add it 
to dependencies of your package to actually use/run it. dub 
does not do actual installation of packages outside of its own 
ecosystem.



besides in https://code.dlang.org/packages/arsd-official they 
said use dub add arsd-official


Instead if specifying a dub package manually in your project 
dub.json thr command dub add will edit the dub.json for you.


Normally you get dub with the dmd/ldc/gdc package. Just 
download/install a recent package compiler package if you want to 
have command dub add.


Kind regards
Andre


Re: Dub version

2019-08-08 Thread greatsam4sure via Digitalmars-d-learn

On Friday, 9 August 2019 at 01:18:12 UTC, Elronnd wrote:

Dub add is not supported in dub 1.11.0


Use 'dub fetch'.




dub fetch dub
Fetching dub 1.16.0...
Please note that you need to use `dub run ` or add it to 
dependencies of your package to actually use/run it. dub does not 
do actual installation of packages outside of its own ecosystem.



besides in https://code.dlang.org/packages/arsd-official they 
said use dub add arsd-official





Re: Dub version

2019-08-08 Thread Elronnd via Digitalmars-d-learn

Dub add is not supported in dub 1.11.0


Use 'dub fetch'.



Dub version

2019-08-08 Thread GreatSam4sure via Digitalmars-d-learn

Which version of dub support dub add library name?

Dub add is not supported in dub 1.11.0

Besides I could not run rdmd on my windows 10 core i7. It days 
this app cannot run on this machine


What is the way out? Where can I get window binary for dub that 
is higher than dub 1.11.0




Re: Module static constructor doesn't work?

2019-08-08 Thread Andrey Zherikov via Digitalmars-d-learn

On Thursday, 8 August 2019 at 16:04:33 UTC, a11e99z wrote:
On Thursday, 8 August 2019 at 14:55:37 UTC, Andrey Zherikov 
wrote:

I have the following code:

// main.d
int main()
{
import std.stdio;
writeln("hello");
return 0;
}

But if I create library from lib.d first and then link it with 
main.d then ctor/dtor are not called:

$ dmd.exe -lib lib1/lib.d -od=lib1
$ dmd.exe main.d lib1/lib.lib && main.exe
hello


try to add to main.d:

import lib1.lib;


Actually importing solved the issue although it's not ideal 
solution IMO. Thanks for your help!


Re: LNK4255 warning - should I be concerned?

2019-08-08 Thread DanielG via Digitalmars-d-learn

(Maybe I should add: this is on DMD 2.086.0, Windows 10)




LNK4255 warning - should I be concerned?

2019-08-08 Thread DanielG via Digitalmars-d-learn
"warning LNK4255: library contain multiple objects of the same 
name; linking object as if no debug info"


Is there some way to get more detail about this warning? Might 
help to know which objects ...


My program is working fine now, but is this going to cause 
problems later on? Like when I want to debug?


Re: Module static constructor doesn't work?

2019-08-08 Thread kinke via Digitalmars-d-learn

On Thursday, 8 August 2019 at 14:55:37 UTC, Andrey Zherikov wrote:
But if I create library from lib.d first and then link it with 
main.d then ctor/dtor are not called:


For this to work as expected, the `lib.obj` object file needs to 
be linked into the final executable. As main.d doesn't need 
anything from lib.d, the linker will skip it by default if it's 
in a static library. An `import lib1.lib` isn't enough, you need 
to reference some symbol in main.d. Or instruct the linker to use 
all object files in the static library (e.g., via /WHOLEARCHIVE 
with the MS linker).


Re: Private variables accessible from outside class

2019-08-08 Thread ag0aep6g via Digitalmars-d-learn

On 08.08.19 18:03, Drobet wrote:

Then why does it in the tour say that it can only be "seen by Integer"?
https://tour.dlang.org/tour/en/basics/classes


That's an error in the tour.


Re: Private variables accessible from outside class

2019-08-08 Thread Drobet via Digitalmars-d-learn

On Thursday, 8 August 2019 at 15:53:13 UTC, Zoadian wrote:


private means module private in D.
see: https://dlang.org/spec/attribute.html#visibility_attributes


Then why does it in the tour say that it can only be "seen by 
Integer"?

https://tour.dlang.org/tour/en/basics/classes


Re: Module static constructor doesn't work?

2019-08-08 Thread a11e99z via Digitalmars-d-learn

On Thursday, 8 August 2019 at 14:55:37 UTC, Andrey Zherikov wrote:

I have the following code:

// main.d
int main()
{
import std.stdio;
writeln("hello");
return 0;
}

But if I create library from lib.d first and then link it with 
main.d then ctor/dtor are not called:

$ dmd.exe -lib lib1/lib.d -od=lib1
$ dmd.exe main.d lib1/lib.lib && main.exe
hello


try to add to main.d:

import lib1.lib;


Re: Private variables accessible from outside class

2019-08-08 Thread Paul Backus via Digitalmars-d-learn

On Thursday, 8 August 2019 at 15:51:45 UTC, Drobet wrote:
I'm having a weird issue, where after defining my classes 
variables as private, they can still be modified and looked at 
from the outside. That leads to this code compiling with no 
issues.


[...]

My question is if this is intended behavior, and if yes, why?


For some context on why private works the way it does in D, take 
a look at this post on the official D blog:


https://dlang.org/blog/2018/11/06/lost-in-translation-encapsulation/


Re: Private variables accessible from outside class

2019-08-08 Thread Ethan via Digitalmars-d-learn

On Thursday, 8 August 2019 at 15:51:45 UTC, Drobet wrote:
I'm having a weird issue, where after defining my classes 
variables as private


https://dlang.org/spec/attribute.html

Section 8.4.2 of the spec reads:

Symbols with private visibility can only be accessed from within 
the same module. Private member functions are implicitly final 
and cannot be overridden.


If you were to put that Vector3 class in another module and 
import it, you'll find that private works as you expect.


You'll find this ability very useful when you start using Uniform 
Function Call Syntax in your code.


https://tour.dlang.org/tour/en/gems/uniform-function-call-syntax-ufcs


Re: Private variables accessible from outside class

2019-08-08 Thread matheus via Digitalmars-d-learn

On Thursday, 8 August 2019 at 15:51:45 UTC, Drobet wrote:

...
My question is if this is intended behavior, and if yes, why?


This is true if the class is inside the same module:

"Private means that only members of the enclosing class can 
access the member, or members and functions in the same module as 
the enclosing class. Private members cannot be overridden."[1]


Matheus.

[1]https://wiki.dlang.org/Access_specifiers_and_visibility




Private variables accessible from outside class

2019-08-08 Thread Drobet via Digitalmars-d-learn
I'm having a weird issue, where after defining my classes 
variables as private, they can still be modified and looked at 
from the outside. That leads to this code compiling with no 
issues.


import std.stdio;

class Vector3
{
this(double _x = 0.0, double _y = 0.0, double _z = 0.0)
{
x = _x;
y = _y;
z = _z;
}

private:
double x, y, z;
}

int main()
{
Vector3 vec = new Vector3(5, 5, 5);
vec.x = 10;
writeln(vec.x);

getchar();

vec.destroy();
return 0;
}

My question is if this is intended behavior, and if yes, why?



Re: Private variables accessible from outside class

2019-08-08 Thread Zoadian via Digitalmars-d-learn

On Thursday, 8 August 2019 at 15:51:45 UTC, Drobet wrote:
I'm having a weird issue, where after defining my classes 
variables as private, they can still be modified and looked at 
from the outside. That leads to this code compiling with no 
issues.


import std.stdio;

class Vector3
{
this(double _x = 0.0, double _y = 0.0, double _z = 0.0)
{
x = _x;
y = _y;
z = _z;
}

private:
double x, y, z;
}

int main()
{
Vector3 vec = new Vector3(5, 5, 5);
vec.x = 10;
writeln(vec.x);

getchar();

vec.destroy();
return 0;
}

My question is if this is intended behavior, and if yes, why?


private means module private in D.
see: https://dlang.org/spec/attribute.html#visibility_attributes



Re: Module static constructor doesn't work?

2019-08-08 Thread Dukc via Digitalmars-d-learn

On Thursday, 8 August 2019 at 14:55:37 UTC, Andrey Zherikov wrote:

I have the following code:

// lib1/lib.d
module lib;

import std.stdio;

static this()
{
writeln("+" ~ __FILE__);
}

static ~this()
{
writeln("-" ~ __FILE__);
}

// main.d
int main()
{
import std.stdio;
writeln("hello");
return 0;
}

So if I compile lib.d and main.d together then ctor/dtor are 
called:

$ dmd.exe main.d lib1/lib.d && main.exe
+lib1\lib.d
hello
-lib1\lib.d

But if I create library from lib.d first and then link it with 
main.d then ctor/dtor are not called:

$ dmd.exe -lib lib1/lib.d -od=lib1
$ dmd.exe main.d lib1/lib.lib && main.exe
hello


I'm looking only quickly without being sure about this, but I 
suspect you are only linking in the binary of `lib.d`. If you do 
that, you need to generate or define a header file for `lib.d`. 
Probably a better idea is to just use the first compiler 
invocation. It should generate an object file of `lib.d` that is 
only recompiled if you change source code of `lib.d`.


If for some reason you need a `.lib` file, I think you want to 
still include `lib.d`. The compiler needs it to know how to use 
the pregenerated binary, including calling those module 
constructors you described.


But take this with a grain of salt, because I haven't done that 
before and don't know the details.


Module static constructor doesn't work?

2019-08-08 Thread Andrey Zherikov via Digitalmars-d-learn

I have the following code:

// lib1/lib.d
module lib;

import std.stdio;

static this()
{
writeln("+" ~ __FILE__);
}

static ~this()
{
writeln("-" ~ __FILE__);
}

// main.d
int main()
{
import std.stdio;
writeln("hello");
return 0;
}

So if I compile lib.d and main.d together then ctor/dtor are 
called:

$ dmd.exe main.d lib1/lib.d && main.exe
+lib1\lib.d
hello
-lib1\lib.d

But if I create library from lib.d first and then link it with 
main.d then ctor/dtor are not called:

$ dmd.exe -lib lib1/lib.d -od=lib1
$ dmd.exe main.d lib1/lib.lib && main.exe
hello