Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Steven Schveighoffer via Digitalmars-d-learn

On 8/27/21 11:43 AM, Ki Rill wrote:

On Friday, 27 August 2021 at 15:24:14 UTC, Steven Schveighoffer wrote:
I suspect your MSVC installation is bad, or there are some other 
switches causing problems.




Hmm... well, I will use the default setup and think about it later.

I mostly use Linux, Windows realm is an uncharted territory for me.


Take my diagnoses with a grain of salt -- I mostly use MacOS and Linux, 
and I'm mostly lost on Windows. I was proficient with Visual C++ 5 or so 
a long time ago ;)


-Steve


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Ki Rill via Digitalmars-d-learn
On Friday, 27 August 2021 at 15:24:14 UTC, Steven Schveighoffer 
wrote:
I suspect your MSVC installation is bad, or there are some 
other switches causing problems.


-Steve


Hmm... well, I will use the default setup and think about it 
later.


I mostly use Linux, Windows realm is an uncharted territory for 
me.


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Steven Schveighoffer via Digitalmars-d-learn

On 8/27/21 11:19 AM, Ki Rill wrote:

On Friday, 27 August 2021 at 14:52:15 UTC, Mike Parker wrote:

On Friday, 27 August 2021 at 14:46:56 UTC, Ki Rill wrote:

On Friday, 27 August 2021 at 13:54:18 UTC, Steven Schveighoffer wrote:

[...]


How do I tell DUB where to look for `raylibdll.lib` and `raylib.dll`? 
Via `lflags` section? What if I put them in a different folder 
instead of the project's directory?


Yes. The path goes in the lflags directive using whatever the 
linker-specific flag is. I assume for lld it's `-Lpath`. For MS link 
it's `/LIBPATH:path`.


To clarify, the .dll file's path is not embedded into the binary. You 
have to add it's path to your "Path" environment variable in order for 
your game to load it.


But you do need the /LIBPATH option to tell it where to find the .lib file.



I've added lfags:
```
"lflags": ["/LIBPATH:C:\\Users\\Username\\Desktop\\test\\source\\"]
```

But now it cannot find the following:
```
msvcrt120.lib
OLDNAMES.lib
shell32.lib
```

I think `lfags` overrides the default search path and I need to add it 
manually as well. But what is that path on Windows?


That shouldn't happen. I've never had to tell it where the default 
libraries are. For sure the lflags does NOT override the default library 
search paths.


I suspect your MSVC installation is bad, or there are some other 
switches causing problems.


-Steve


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Steven Schveighoffer via Digitalmars-d-learn

On 8/27/21 10:35 AM, Ki Rill wrote:

On Friday, 27 August 2021 at 13:54:18 UTC, Steven Schveighoffer wrote:
In the end, I got it to build and run, but I'd highly recommend just 
linking against the `raylibdll.lib` and using the dll.




Steve, thank you! I got it working with `raylibdll.lib`!


Yes, either 3.5.0 or 3.7.0, they now build with 2 types of libs, static 
and dynamic. The raylib.lib file is for static linking, the 
raylibdll.lib file is for DLL.


Glad you got it working!

4. put `raylib.dll` and `raylibdll.lib` into your project's folder (into 
the same directory, where you have `dub.json`)


You know, I taught a class using raylib and D (I learned a lot from your 
video series, thanks!), and I didn't even think about just copy the 
libraries to your project directory as a "step". Instead I had them put 
in the /LIBDIR flags to wherever they installed it.


This way is MUCH easier, I think I'll switch to that.

dub in general has some rough edges when linking against libraries that 
aren't in default locations. Having to edit the dub.json file is sub-par.


-Steve


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Ki Rill via Digitalmars-d-learn

On Friday, 27 August 2021 at 14:52:15 UTC, Mike Parker wrote:

On Friday, 27 August 2021 at 14:46:56 UTC, Ki Rill wrote:
On Friday, 27 August 2021 at 13:54:18 UTC, Steven 
Schveighoffer wrote:

[...]


How do I tell DUB where to look for `raylibdll.lib` and 
`raylib.dll`? Via `lflags` section? What if I put them in a 
different folder instead of the project's directory?


Yes. The path goes in the lflags directive using whatever the 
linker-specific flag is. I assume for lld it's `-Lpath`. For MS 
link it's `/LIBPATH:path`.


I've added lfags:
```
"lflags": 
["/LIBPATH:C:\\Users\\Username\\Desktop\\test\\source\\"]

```

But now it cannot find the following:
```
msvcrt120.lib
OLDNAMES.lib
shell32.lib
```

I think `lfags` overrides the default search path and I need to 
add it manually as well. But what is that path on Windows?


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Mike Parker via Digitalmars-d-learn

On Friday, 27 August 2021 at 14:46:56 UTC, Ki Rill wrote:
On Friday, 27 August 2021 at 13:54:18 UTC, Steven Schveighoffer 
wrote:

[...]


How do I tell DUB where to look for `raylibdll.lib` and 
`raylib.dll`? Via `lflags` section? What if I put them in a 
different folder instead of the project's directory?


Yes. The path goes in the lflags directive using whatever the 
linker-specific flag is. I assume for lld it's `-Lpath`. For MS 
link it's `/LIBPATH:path`.


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Ki Rill via Digitalmars-d-learn
On Friday, 27 August 2021 at 13:54:18 UTC, Steven Schveighoffer 
wrote:

[...]


How do I tell DUB where to look for `raylibdll.lib` and 
`raylib.dll`? Via `lflags` section? What if I put them in a 
different folder instead of the project's directory?


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Ki Rill via Digitalmars-d-learn

On Friday, 27 August 2021 at 13:54:25 UTC, Mike Parker wrote:
But assuming you are on a 64-bit system, the DMD will use 
Visual Studio's linker if you have it installed. If you don't, 
it will use the lld linker it ships with. Either way, you need 
to raylib to be compiled with he same version of the MS Build 
tools so that you don't have conflicts the the vs runtime.


Indeed, DMD used the lld linker.


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Ki Rill via Digitalmars-d-learn
On Friday, 27 August 2021 at 13:54:18 UTC, Steven Schveighoffer 
wrote:
In the end, I got it to build and run, but I'd highly recommend 
just linking against the `raylibdll.lib` and using the dll.


-Steve


Steve, thank you! I got it working with `raylibdll.lib`!

SOLUTION:
1. `dub init`

2. `dub add raylib-d`

3. download `raylib` pre-compiled 
[binaries](https://github.com/raysan5/raylib/releases) for 
Microsoft Visual Studio (msvs)


4. put `raylib.dll` and `raylibdll.lib` into your project's 
folder (into the same directory, where you have `dub.json`)


5. add `"libs":["raylibdll"]` section into dub.json

Compile and run. It should work.


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Mike Parker via Digitalmars-d-learn

On Friday, 27 August 2021 at 13:41:56 UTC, Ki Rill wrote:



I have downloaded the pre-compiled binaries from the official 
[Raylib ](https://github.com/raysan5/raylib/releases/tag/3.7.0) 
repo.


I'm not using Visual Studio. Only dub and a text editor.


But assuming you are on a 64-bit system, the DMD will use Visual 
Studio's linker if you have it installed. If you don't, it will 
use the lld linker it ships with. Either way, you need to raylib 
to be compiled with he same version of the MS Build tools so that 
you don't have conflicts the the vs runtime.


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Steven Schveighoffer via Digitalmars-d-learn

On 8/27/21 9:21 AM, Ki Rill wrote:
I have a Raylib project on Windows using DUB. I've added raylib-d via 
`dub add`. But what I can't figure out is how to tell DUB to link 
against raylib library.


I have the following project structure:
```
-> source
---> app.d
-> libraylib.a
-> raylib.dll
-> etc...
```

I'd like to use either .a or .dll. Do you have any ideas?


I spent a lot of time trying to figure this out (someone in discord 
really wanted to link statically for some reason). I FINALLY got a 
statically linked exe, but it's not worth the effort. I had to:


1. update my msvc build tools to match what was used for the official 
release (alternatively, you can rebuild the raylib library with your 
tools, otherwise you get cryptic errors like `fatal error C1900: Il 
mismatch between 'P1' version '20210113' and 'P2' version '20190715'`).

2. pass in cryptic linker options like `/NODEFAULTLIB:libcmt`, etc.
3. Link against extra libraries until the linker errors disappear 
(google search for missing symbols to see what libraries those symbols 
are in).


My eventual resulting dub.json looked like (you can guess where I put 
things):


```json
{
"name": "rps-explosion",
"dependencies": {
"jsoniopipe": "~>0.1.3",
"enet-d": "~>0.0.1",
"raylib-d": "~>3.1.0"
},
"libs": ["enet", "raylib", "ws2_32", "winmm", "msvcrt", "user32", 
"gdi32"],

"lflags": ["/LIBPATH:C:\\dprojects\\enet-1.3.17",
"/LIBPATH:C:\\dprojects\\raylib-3.7.0_win64_msvc16\\lib", 
"/NODEFAULTLIB:libcmt", "/NODEFAULTLIB:libvcruntime"]

}
```

This config also included `enet-d` so some of the linker options are for 
that lib.


In the end, I got it to build and run, but I'd highly recommend just 
linking against the `raylibdll.lib` and using the dll.


-Steve


Re: A way to mixin during runtime?

2021-08-27 Thread Steven Schveighoffer via Digitalmars-d-learn

On 8/27/21 6:34 AM, Kirill wrote:

On Friday, 27 August 2021 at 09:51:46 UTC, Mathias LANG wrote:

On Friday, 27 August 2021 at 06:52:10 UTC, Kirill wrote:

Is there a way to do mixin or similar during runtime?

I'm trying to read a csv file and extract data types. Any ideas on 
how this should be approached in D are greatly appreciated.


You cannot mixin at runtime. However, it is fairly easy to map a 
finite and CT-know set of argument to runtime arguments via `static 
foreach`.
Could you give us example of the content of your CSV file and what you 
are trying to do ?


Each csv file will be different.

For example:
```
name;surname;age;grade
Alex;Wong;18;87
John;Doe;19;65
Alice;Doe;18;73
etc...
```

I'd like to extract the data types automatically. For instance, if using 
tuples:

```
Tuple!(string, string, int, int) ...
```
instead I'd like to have:
```
auto mytuple = read_csv(path); // returns Tuple!(string, string, int, 
int)[]

```


So you can't build "new types" at runtime that are usable after your 
code is compiled. But there are options:


1. You can parse the CSV at compile-time using `import("types.csv");` 
and then processing the resulting string using CTFE (not sure if std.csv 
does this, but I'd expect it to). Then you can use the resulting thing 
to generate string mixins that can generate types. This has the drawback 
that you need to recompile when your csv input changes.


2. You can create a dynamic type that deals with the CSV data. It looks 
from your CSV data you are inferring the "type" from the data itself, 
which is complex in itself. In this case, you'd use it kind of like a 
JSON object, where you index the fields by name instead of using 
`obj.name`, and you'd have to extract the type dynamically from the type 
inference you'd have to write. This is pretty much what std.csv does, 
though you can dress it up a bit more.


Without the CSV telling you types, it's hard to make something "easy". I 
have written code that extracts from JSON data and database data 
serializable struct types, and builds a D file, but it's never 
clean-cut, and sometimes you have to hand-edit that stuff. This is about 
as "easy" as it gets, just have the computer do most of the heavy 
lifting, and then massage it into something usable.


-Steve


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Ki Rill via Digitalmars-d-learn

On Friday, 27 August 2021 at 13:33:25 UTC, Mike Parker wrote:

On Friday, 27 August 2021 at 13:21:04 UTC, Ki Rill wrote:
I have a Raylib project on Windows using DUB. I've added 
raylib-d via `dub add`. But what I can't figure out is how to 
tell DUB to link against raylib library.


I have the following project structure:
```
-> source
---> app.d
-> libraylib.a
-> raylib.dll
-> etc...
```

I'd like to use either .a or .dll. Do you have any ideas?


raylib.a isn't going to get you anywhere. You'll run into 
issues mixing MinGW-compiled libraries.


If raylib doesn't ship precompiled VS binaries, then, assuming 
you have Visual Studio (or the MS Build tools) installed, you 
should compile Raylib with that same version. Then you'll have 
a new raylib.dll and a raylib.lib. Add raylib.lib to your dub 
config via the "libs" directive.


I have downloaded the pre-compiled binaries from the official 
[Raylib ](https://github.com/raysan5/raylib/releases/tag/3.7.0) 
repo.


I'm not using Visual Studio. Only dub and a text editor.


Re: A little help with Ranges

2021-08-27 Thread Steven Schveighoffer via Digitalmars-d-learn

On 8/27/21 12:41 AM, Merlin Diavova wrote:

On Friday, 27 August 2021 at 04:01:19 UTC, Ali Çehreli wrote:

On 8/26/21 7:17 PM, Merlin Diavova wrote:


[...]


Then the operations downstream will not produce any results. For 
example, the array will be empty below:


import std.stdio;
import std.range;
import std.algorithm;
import std.string;
import std.functional;

void main() {
  auto significantLines = stdin
  .byLineCopy
  .map!strip
  .filter!(not!empty)
  .filter!(line => line.front != '#')
  .array;

  if (significantLines.empty) {
    writeln("There were no significant lines.");

  } else {
    writefln!"The lines: %-(\n%s%)"(significantLines);
  }
}

Ali


And there it is!

I was missing

```d
.filter!(not!empty)
```

My code now works exactly how I wanted. Thanks!


Be careful with this! `not!empty` is *only* working because you are 
using arrays (where `empty` is a UFCS function defined in std.range). 
Other ranges this will not work on. Instead, I would recommend a lambda 
(which will work with arrays too):


```d
.filter!(r => !r.empty)
```

-Steve


Re: DUB: How to link an external library on Windows 10?

2021-08-27 Thread Mike Parker via Digitalmars-d-learn

On Friday, 27 August 2021 at 13:21:04 UTC, Ki Rill wrote:
I have a Raylib project on Windows using DUB. I've added 
raylib-d via `dub add`. But what I can't figure out is how to 
tell DUB to link against raylib library.


I have the following project structure:
```
-> source
---> app.d
-> libraylib.a
-> raylib.dll
-> etc...
```

I'd like to use either .a or .dll. Do you have any ideas?


raylib.a isn't going to get you anywhere. You'll run into issues 
mixing MinGW-compiled libraries.


If raylib doesn't ship precompiled VS binaries, then, assuming 
you have Visual Studio (or the MS Build tools) installed, you 
should compile Raylib with that same version. Then you'll have a 
new raylib.dll and a raylib.lib. Add raylib.lib to your dub 
config via the "libs" directive.





DUB: How to link an external library on Windows 10?

2021-08-27 Thread Ki Rill via Digitalmars-d-learn
I have a Raylib project on Windows using DUB. I've added raylib-d 
via `dub add`. But what I can't figure out is how to tell DUB to 
link against raylib library.


I have the following project structure:
```
-> source
---> app.d
-> libraylib.a
-> raylib.dll
-> etc...
```

I'd like to use either .a or .dll. Do you have any ideas?


Re: A way to mixin during runtime?

2021-08-27 Thread jfondren via Digitalmars-d-learn

On Friday, 27 August 2021 at 10:34:27 UTC, Kirill wrote:

Each csv file will be different.

For example:
```
name;surname;age;grade
Alex;Wong;18;87
John;Doe;19;65
Alice;Doe;18;73
etc...
```

I'd like to extract the data types automatically. For instance, 
if using tuples:

```
Tuple!(string, string, int, int) ...
```
instead I'd like to have:
```
auto mytuple = read_csv(path); // returns Tuple!(string, 
string, int, int)[]

```


mytuple needs to have a type that's known at compile-time, so 
this isn't possible. In the types are only dynamically known, 
then you have to deal in dynamic types. One way could be to have 
a read_csv that returns an array of 
https://dlang.org/phobos/std_variant.html


Re: A way to mixin during runtime?

2021-08-27 Thread Kirill via Digitalmars-d-learn

On Friday, 27 August 2021 at 09:51:46 UTC, Mathias LANG wrote:

On Friday, 27 August 2021 at 06:52:10 UTC, Kirill wrote:

Is there a way to do mixin or similar during runtime?

I'm trying to read a csv file and extract data types. Any 
ideas on how this should be approached in D are greatly 
appreciated.


You cannot mixin at runtime. However, it is fairly easy to map 
a finite and CT-know set of argument to runtime arguments via 
`static foreach`.
Could you give us example of the content of your CSV file and 
what you are trying to do ?


Each csv file will be different.

For example:
```
name;surname;age;grade
Alex;Wong;18;87
John;Doe;19;65
Alice;Doe;18;73
etc...
```

I'd like to extract the data types automatically. For instance, 
if using tuples:

```
Tuple!(string, string, int, int) ...
```
instead I'd like to have:
```
auto mytuple = read_csv(path); // returns Tuple!(string, string, 
int, int)[]

```


Re: A way to mixin during runtime?

2021-08-27 Thread Mathias LANG via Digitalmars-d-learn

On Friday, 27 August 2021 at 06:52:10 UTC, Kirill wrote:

Is there a way to do mixin or similar during runtime?

I'm trying to read a csv file and extract data types. Any ideas 
on how this should be approached in D are greatly appreciated.


You cannot mixin at runtime. However, it is fairly easy to map a 
finite and CT-know set of argument to runtime arguments via 
`static foreach`.
Could you give us example of the content of your CSV file and 
what you are trying to do ?


Re: A way to mixin during runtime?

2021-08-27 Thread dangbinghoo via Digitalmars-d-learn

On Friday, 27 August 2021 at 06:52:10 UTC, Kirill wrote:

Is there a way to do mixin or similar during runtime?

I'm trying to read a csv file and extract data types. Any ideas 
on how this should be approached in D are greatly appreciated.


remember D is a statically compiled language, `mixin` is for 
generating code, so, it won't work except you have a runtime code 
parser.


you may need a scripting language embedded in your D app to 
achieve this.



thx.


A way to mixin during runtime?

2021-08-27 Thread Kirill via Digitalmars-d-learn

Is there a way to do mixin or similar during runtime?

I'm trying to read a csv file and extract data types. Any ideas 
on how this should be approached in D are greatly appreciated.