Re: dlib 0.19.1 seems to be failing linking with ldc2

2020-08-02 Thread jeff thompson via Digitalmars-d-learn

On Friday, 31 July 2020 at 22:26:26 UTC, jeff thompson wrote:

On Friday, 31 July 2020 at 20:07:26 UTC, Dennis wrote:

On Friday, 31 July 2020 at 14:17:14 UTC, jeff thompson wrote:
dlib.lib(dlib.audio.io.wav.obj) : error LNK2019: unresolved 
external symbol 
_D4core8internal7switch___T14__switch_errorZQrFNaNbNiNfAyamZv 
referenced in function 
_D3std6format__T10printFloatTfTaZQrFNaNfNkAafSQBsQBr__T10FormatSpecTaZQpEQCtQCs12RoundingModeZQCa
dlib.lib(dlib.filesystem.local.obj) : error LNK2001: 
unresolved external symbol 
_D4core8internal7switch___T14__switch_errorZQrFNaNbNiNfAyamZv

.dub\build\application-debug-windows-x86_64-ldc_2092-316AB5B187D20C1F6AFBA496E604908D\test.exe
 : fatal error LNK1120: 1 unresolved externals



The first thing you want to do is demangle the symbols so you 
know what they really are.

You can use the tool `ddemangle` for that:
```
echo 
'_D3std6format__T10printFloatTfTaZQrFNaNfNkAafSQBsQBr__T10FormatSpecTaZQpEQCtQCs12RoundingModeZQCa' | ddemangle

```

You'll find that this symbol is missing:

pure nothrow @nogc @safe void 
core.internal.switch_.__switch_error!().__switch_error(immutable(char)[], ulong)


And it's used in this function:

pure @safe char[] std.format.printFloat!(float, 
char).printFloat(return char[], float, 
std.format.FormatSpec!(char).FormatSpec, 
std.format.RoundingMode)


The switch_error function is called when none of the cases of 
a `final switch` apply. There is a final switch in 
std.format.printFloat:

https://github.com/ldc-developers/phobos/blob/c43cafe53746a07dee8fa9e00d3a2256c7f05506/std/format.d#L7096

So why is the compiler not emitting the final switch error 
template function? I am not sure, it could be a bug, or maybe 
you have some funky dub settings. You might be able to work 
around this by defining a final switch in you own code 
somewhere, or explicitly defining the function.


```
pragma(mangle, 
"_D4core8internal7switch___T14__switch_errorZQrFNaNbNiNfAyamZv")

void switchError(string file, ulong line) {
assert(0, file);
}
```

I hope someone else with more familiarity of how template 
symbols are emitted can find the root of this problem and give 
a proper fix.


Thanks! From looking at it, isn't happening in 
dlib.lib(dlib.audio.io.wav.obj)? Also this is with a test 
program with nothing but an empty main and a dependency on dlib 
0.19.1. I
 guess ill post something in their github since it does compile 
and link with dmd


Ok so the scenario is a dub project A that has a dependency on 
another dub project B who is using dlib. Compiling project A with 
the dependency with ldc produces the error


Re: dlib 0.19.1 seems to be failing linking with ldc2

2020-07-31 Thread jeff thompson via Digitalmars-d-learn

On Friday, 31 July 2020 at 20:07:26 UTC, Dennis wrote:

On Friday, 31 July 2020 at 14:17:14 UTC, jeff thompson wrote:
dlib.lib(dlib.audio.io.wav.obj) : error LNK2019: unresolved 
external symbol 
_D4core8internal7switch___T14__switch_errorZQrFNaNbNiNfAyamZv 
referenced in function 
_D3std6format__T10printFloatTfTaZQrFNaNfNkAafSQBsQBr__T10FormatSpecTaZQpEQCtQCs12RoundingModeZQCa
dlib.lib(dlib.filesystem.local.obj) : error LNK2001: 
unresolved external symbol 
_D4core8internal7switch___T14__switch_errorZQrFNaNbNiNfAyamZv

.dub\build\application-debug-windows-x86_64-ldc_2092-316AB5B187D20C1F6AFBA496E604908D\test.exe
 : fatal error LNK1120: 1 unresolved externals



The first thing you want to do is demangle the symbols so you 
know what they really are.

You can use the tool `ddemangle` for that:
```
echo 
'_D3std6format__T10printFloatTfTaZQrFNaNfNkAafSQBsQBr__T10FormatSpecTaZQpEQCtQCs12RoundingModeZQCa' | ddemangle

```

You'll find that this symbol is missing:

pure nothrow @nogc @safe void 
core.internal.switch_.__switch_error!().__switch_error(immutable(char)[], ulong)


And it's used in this function:

pure @safe char[] std.format.printFloat!(float, 
char).printFloat(return char[], float, 
std.format.FormatSpec!(char).FormatSpec, 
std.format.RoundingMode)


The switch_error function is called when none of the cases of a 
`final switch` apply. There is a final switch in 
std.format.printFloat:

https://github.com/ldc-developers/phobos/blob/c43cafe53746a07dee8fa9e00d3a2256c7f05506/std/format.d#L7096

So why is the compiler not emitting the final switch error 
template function? I am not sure, it could be a bug, or maybe 
you have some funky dub settings. You might be able to work 
around this by defining a final switch in you own code 
somewhere, or explicitly defining the function.


```
pragma(mangle, 
"_D4core8internal7switch___T14__switch_errorZQrFNaNbNiNfAyamZv")

void switchError(string file, ulong line) {
assert(0, file);
}
```

I hope someone else with more familiarity of how template 
symbols are emitted can find the root of this problem and give 
a proper fix.


Thanks! From looking at it, isn't happening in 
dlib.lib(dlib.audio.io.wav.obj)? Also this is with a test program 
with nothing but an empty main and a dependency on dlib 0.19.1. I 
 guess ill post something in their github since it does compile 
and link with dmd


Re: dlib 0.19.1 seems to be failing linking with ldc2

2020-07-31 Thread jeff thompson via Digitalmars-d-learn

Also this is on x86_x64 box and the 2019 MSVC toolchain




dlib 0.19.1 seems to be failing linking with ldc2

2020-07-31 Thread jeff thompson via Digitalmars-d-learn

Hello

Im using dlib 0.19.1 with a project and compiling with ldc2 1.22 
its failing with the error below. This works fine with the latest 
dmd version. My targetType is a static lib, only other 
dependencies are latest bindbc-glfw and bindbc-gl


Performing "debug" build using ldc2.exe for x86_64.
dlib ~master: target for configuration "library" is up to date.
sandbox ~master: building configuration "application"...
Linking...
dlib.lib(dlib.audio.io.wav.obj) : error LNK2019: unresolved 
external symbol 
_D4core8internal7switch___T14__switch_errorZQrFNaNbNiNfAyamZv 
referenced in function 
_D3std6format__T10printFloatTfTaZQrFNaNfNkAafSQBsQBr__T10FormatSpecTaZQpEQCtQCs12RoundingModeZQCa
dlib.lib(dlib.filesystem.local.obj) : error LNK2001: unresolved 
external symbol 
_D4core8internal7switch___T14__switch_errorZQrFNaNbNiNfAyamZv

.dub\build\application-debug-windows-x86_64-ldc_2092-316AB5B187D20C1F6AFBA496E604908D\test.exe
 : fatal error LNK1120: 1 unresolved externals

Anyone else seeing this?


Re: dub build to generate different kinds of libs

2020-07-29 Thread jeff thompson via Digitalmars-d-learn

On Wednesday, 29 July 2020 at 13:26:45 UTC, Andre Pany wrote:

On Tuesday, 28 July 2020 at 22:10:58 UTC, jeff thompson wrote:
On Tuesday, 28 July 2020 at 22:08:14 UTC, Steven Schveighoffer 
wrote:

[...]


Thanks Steve!, ya i know i can call build twice but i was 
wondering if there was any config magic for dub to make it 
output multiple library types in one call to build


As far as I remember if you set the targetType of the main 
package to none it build all the sub packages in one call. 
Therefore you have 2 sub packages instead of 2 configurations.


But I have to say I have never done it myself, but just saw the 
pr which should implement this behavior.


Kind regards
Andre


Awesome, cant wait to get that ability, as far as my issue i was 
being a D newb and was setting everything up incorrectly. Im all 
good now. Thanks


-J


Re: dub build to generate different kinds of libs

2020-07-28 Thread jeff thompson via Digitalmars-d-learn
On Tuesday, 28 July 2020 at 22:08:14 UTC, Steven Schveighoffer 
wrote:

On 7/28/20 5:50 PM, jeff thompson wrote:

Hello

Im brand new to D (loving it btw!) and have decided to build a 
largish windows project in the language. First question, is 
there a dub.json setup to have a dub build to generate 
multiple binaries in one call? Like a dll and a static lib. 
Seems like it would be easy maybe im missing something 
obvious? Like a configuration with multiple targetTypes.


Yes, just do that (make multiple configurations)

You just have to build them separately:

dub build --config=library
dub build --config=application

-Steve


I got it figured out, thank you


Re: dub build to generate different kinds of libs

2020-07-28 Thread jeff thompson via Digitalmars-d-learn
On Tuesday, 28 July 2020 at 22:08:14 UTC, Steven Schveighoffer 
wrote:

On 7/28/20 5:50 PM, jeff thompson wrote:

Hello

Im brand new to D (loving it btw!) and have decided to build a 
largish windows project in the language. First question, is 
there a dub.json setup to have a dub build to generate 
multiple binaries in one call? Like a dll and a static lib. 
Seems like it would be easy maybe im missing something 
obvious? Like a configuration with multiple targetTypes.


Yes, just do that (make multiple configurations)

You just have to build them separately:

dub build --config=library
dub build --config=application

-Steve


Thanks Steve!, ya i know i can call build twice but i was 
wondering if there was any config magic for dub to make it output 
multiple library types in one call to build


dub build to generate different kinds of libs

2020-07-28 Thread jeff thompson via Digitalmars-d-learn

Hello

Im brand new to D (loving it btw!) and have decided to build a 
largish windows project in the language. First question, is there 
a dub.json setup to have a dub build to generate multiple 
binaries in one call? Like a dll and a static lib. Seems like it 
would be easy maybe im missing something obvious? Like a 
configuration with multiple targetTypes.


Thanks
J


Re: dub build to generate different kinds of libs

2020-07-28 Thread jeff thompson via Digitalmars-d-learn
I saw this 
https://github.com/dlang/dub/wiki/Cookbook#creating-a-library-package-that-also-comes-with-an-executable


But it didnt result in creating both a dll or exe and a .lib


Re: "inline" conversion of array to immutable

2016-04-22 Thread Jeff Thompson via Digitalmars-d-learn

On Friday, 22 April 2016 at 11:16:59 UTC, ag0aep6g wrote:
It's a nested function now. That means, it could reference 
local variables of main. Make func static and it works.


You can also use a function literal:

void main()
{
  immutable int[] array = {
int[] result = new int[10];
result[0] = 1;
return result;
  }();
}


Great! Making it static works. The function literal also works if 
I add "function int[]()":

void main(string[] args) {
  immutable int[] array = function int[]() {
int[] result = new int[10];
result[0] = 1;
return result;
  }();
}



Re: "inline" conversion of array to immutable

2016-04-22 Thread Jeff Thompson via Digitalmars-d-learn

On Friday, 22 April 2016 at 09:40:14 UTC, FreeSlave wrote:

On Friday, 22 April 2016 at 09:25:32 UTC, Jeff Thompson wrote:
Hello. The following code compiles OK where func creates a 
mutable array and main assigns it to an immutable variable:


[...]


Probably this is what you look for 
http://dlang.org/phobos/std_exception.html#.assumeUnique


OK, we lose the compiler check for correctness. What if I put 
func directly in main with the hopes that the compiler will check 
correctness and also inline the function? But it won't assign to 
the immutable array. Why not? It's the same function.


void main(string[] args) {
  int[] func(int x) pure {
int[] result = new int[10];
result[0] = x;
return result;
  }
  immutable int[] array = func(1);
}



"inline" conversion of array to immutable

2016-04-22 Thread Jeff Thompson via Digitalmars-d-learn
Hello. The following code compiles OK where func creates a 
mutable array and main assigns it to an immutable variable:


int[] func(int x) pure {
  int[] result = new int[10];
  result[0] = x;
  return result;
}

void main(string[] args)
{
  immutable int[] array = func(1);
}

I assume this works because func is pure so that the compiler 
knows that its return value won't be changed by some other code. 
But it doesn't compile when I put the same code from func 
"inline" into main:


void main(string[] args)
{
  int[] result = new int[10];
  result[0] = 1;
  immutable int[] array = result;
}

I could forcibly cast result to immutable int[], but that seems 
error-prone. How to tell the compiler that result will not be 
changed after assigning to array so that the immutable assignment 
compiles?


Re: immutable array in constructor

2016-03-19 Thread Jeff Thompson via Digitalmars-d-learn

On Thursday, 17 March 2016 at 11:27:01 UTC, Rene Zwanenburg wrote:

On Thursday, 17 March 2016 at 10:11:43 UTC, Jeff Thompson wrote:
This is a simplified example from a larger class I have where 
I need an immutable constructor. This is because I need to 
construct an object an pass it to other functions which take 
an immutable object. So, how to keep an immutable constructor?


In that case, new immutable C() should work I believe. Also, if 
you mark the constructor as pure, new C() should be implicitly 
convertible to an immutable C.


new immutable C() worked! Thanks for the insight.


Re: immutable array in constructor

2016-03-19 Thread Jeff Thompson via Digitalmars-d-learn

On Thursday, 17 March 2016 at 10:04:53 UTC, Anonymouse wrote:

On Thursday, 17 March 2016 at 09:57:37 UTC, Jeff Thompson wrote:
In the following code, I explicitly declare array as 
immutable. But it compiles with the error shown below in the 
comment. The array object is declared immutable, so how can 
the compiler say it is a mutable object? In summary, how to 
pass an immutable array to an immutable constructor?


class C {
  int i;
  this(immutable int[] array) immutable {
i = array[0];
  }
}

void func() {
  immutable int[] array = [1];
  auto c = new C(array); // Error: immutable method C.this is 
not callable using a mutable object

}


The error message isn't very good, but remove immutable from 
the constructor and it works.

  this(immutable int[] array) {


This is a simplified example from a larger class I have where I 
need an immutable constructor. This is because I need to 
construct an object an pass it to other functions which take an 
immutable object. So, how to keep an immutable constructor?


immutable array in constructor

2016-03-18 Thread Jeff Thompson via Digitalmars-d-learn
In the following code, I explicitly declare array as immutable. 
But it compiles with the error shown below in the comment. The 
array object is declared immutable, so how can the compiler say 
it is a mutable object? In summary, how to pass an immutable 
array to an immutable constructor?


class C {
  int i;
  this(immutable int[] array) immutable {
i = array[0];
  }
}

void func() {
  immutable int[] array = [1];
  auto c = new C(array); // Error: immutable method C.this is not 
callable using a mutable object

}