Precision Error?
float computeToFitInWindow(uint rows, uint cols) { // code removed ... writeln(hexWidth); return hexWidth; } unittest { assert(computeToFitInWindow(1, 1) == 2.0f, "This assert failed"); assert(computeToFitInWindow(3, 3) == 0.8f, "This assert failed"); assert(computeToFitInWindow(2, 2) == 1.14286f, "This assert failed"); // Line 74 } 2 0.8 1.14286 main.d(74): [unittest] This assert failed Can someone tell me why line 74 fails? Aren't they both 1.14286? I presume it has to do with precision. Is there a technique to address this issue.
Re: 12 line program... `main` is a nested function when trying to use redblacktree. Beginner error???
Thanks, that did the trick. Not sure why having the declarations at global scope (or is it module scope in D) would work versus having them at local scope?
12 line program... `main` is a nested function when trying to use redblacktree. Beginner error???
import std.container : RedBlackTree; int main() { struct Location { int x; int y; } struct Node{ this(Location loc, uint f) { this.loc = loc; this.f = f; } Location loc; uint f; } auto priorityQueue = new RedBlackTree!(Node, "a.f < b.f", true); // true: allowDuplicates // C:\D\dmd2\windows\bin64\..\..\src\phobos\std\container\rbtree.d(806): Error: `main` is // a nested function and cannot be accessed from // `std.container.rbtree.RedBlackTree!(Node, "a.f < b.f", true).RedBlackTree.allocate` return 0; }
Anybody know about SDL and particularly SDL_TTF initialization?
This should be trivial, right? I've been looking at existing D repo code for hours. Can't figure why TTF_Init doesn't work? It would help if I could figure out how to use SDL_GetError() INFO: SDL loaded v2.30.2 INFO: SDL initialized: 0 INFO: TTF loaded: v2.0.14 Error Program exited with code -1073741819 loadSDL(); SDL_version v; SDL_GetVersion(&v); toStdout("SDL loaded v%d.%d.%d", v.major, v.minor, v.patch); auto initSDL = SDL_Init(SDL_INIT_EVERYTHING); // returns 0 on success toStdout("SDL initialized: %d", initSDL); auto loadTTF = loadSDLTTF(); SDL_TTF_VERSION(&v); toStdout("TTF loaded: v%d.%d.%d", v.major, v.minor, v.patch); auto initTTF = TTF_Init(); // SDL must be initialized before calls to this library
What I thought was straightforward blew up in my face..
import bindbc.sdl; import bindbc.loader; SDL_version ver; SDL_GetVersion(&ver); writeln("version = ", ver); // runs and displays: version = SDL_version(2, 30, 2) writeln("version = ", SDL_GetVersion(&ver)); // compile fails with // template `writeln` is not callable using argument types `!()(string, void)` // C:\D\dmd2\windows\bin64\..\..\src\phobos\std\stdio.d(4249,6): Candidate is: `writeln(T...)(T args)` // Error C:\D\dmd2\windows\bin64\dmd.exe failed with exit code 1. I'll confess I can't make heads or tails out of the error messages. Is this impossible or is there some way to make writeln happy?
How to resolve two packages requiring different versions of another package?
Error: Unresolvable dependencies to package bindbc-loader: bindbc-opengl 0.13.0 depends on bindbc-loader ~>0.3.0 bindbc-sdl 1.4.7 depends on bindbc-loader ~>1.1.0
Boneheaded question regarding compilation...
Huge fan of Mike Shah's YouTube videos regarding D and his latest for D conference: https://mshah.io/conf/24/DConf%20%20Online%202024%20_%20The%20Case%20for%20Graphics%20Programming%20in%20Dlang.pdf So I installed github desktop app and cloned his Talks repo. There is a build command commented out at the top of the main.d file which I've been trying to compile, via the command line: C:\Users\kheas\Documents\Talks\2024\dconf_online\hello_triangle>dmd -g -J. main.d ./glad/gl/*.d -L-L/usr/local/lib -L-lglfw3 -of=prog && ./prog Error: cannot find input file `.\glad\gl\*.d` import path[0] = C:\D\dmd2\windows\bin64\..\..\src\phobos import path[1] = C:\D\dmd2\windows\bin64\..\..\src\druntime\import I'm using a Windows 11 machine so I thought that maybe the syntax was for Linux environment. But replacing all the '/' with '\' did not work.
At D-Conf, Mike Shah's students presented a project. Is it in GitHub? Cant find it.
Wanted to study code. I watched the video talk. But i couldn't see any URL etc.. Believe it was called Draw.
Re: quick question, probably of little importance...
On Wednesday, 26 April 2023 at 23:02:07 UTC, Richard (Rikki) Andrew Cattermole wrote: Don't forget ``num % 2 == 0``. None should matter, pretty much all production compilers within the last 30 years should recognize all forms of this and do the right thing. Thanks. Fastest reply ever! And I believe across the world? I suppose my examples required overhead of a function call. So maybe num % 2 == 0 is fastest?
quick question, probably of little importance...
I just need an even/odd functionality. Don't think D has a built-in operator. // Found this C code online. int isEven(int num) { return !(num & 1); } // found this in std.functional.unaryFun alias isEven = unaryFun!("(a & 1) == 0"); assert(isEven(2) && !isEven(1)); If interested just in speed, is either one faster?
Re: Watch me beat a dead horse. Super simple program...
On Wednesday, 22 March 2023 at 21:08:23 UTC, Richard (Rikki) Andrew Cattermole wrote: I finally went ahead and looked at the dependencies of FreeImage3180. Try installing: https://www.microsoft.com/en-ca/download/details.aspx?id=48145 It requires VCOMP140.dll which comes with the 2015 VC redistribution package. Found via: https://github.com/lucasg/Dependencies Yes! Thank you very much. Downloaded the 2015 Microsoft Visual C++ Redistributables and it worked. You mentioning "dependencies" in an earlier post, but didn't know how to proceed. Would it be worth while to update the bindbc-FreeImage documentation or is this common knowledge?
Watch me beat a dead horse. Super simple program...
Ok, I've gotten rid of dub and dub packages code. Just LoadLibraryA. All eight dlls work except for FreeImage.dll. I've compiled with dmd and -m64 option and freshly download a x64 FreeImage. Any Window users out there that use LoadLibraryA or FreeImage.dll? ``` import std.stdio: writeln; import std.string: toStringz; import core.sys.windows.windows: LoadLibraryA; void main() { string[] DLLs = [ "assimp.dll", "fmod.dll", "freetype.dll", "glfw3.dll", "OpenAL32.dll", "SDL2.dll", "SDL2_mixer.dll", "FreeImage.dll" ]; foreach(dll; DLLs) { void *ptr = LoadLibraryA(toStringz(dll)); if (ptr) writeln("calling LoadLibraryA with ", dll, " ptr is set"); else writeln("calling LoadLibraryA with ", dll, " ptr is NULL"); } } ``` C:\Users\Admin\Documents\GitHub\Delivery\apps\00_03_freeimage_debug>app.exe calling LoadLibraryA with assimp.dll ptr is set calling LoadLibraryA with fmod.dll ptr is set calling LoadLibraryA with freetype.dll ptr is set calling LoadLibraryA with glfw3.dll ptr is set calling LoadLibraryA with OpenAL32.dll ptr is set calling LoadLibraryA with SDL2.dll ptr is set calling LoadLibraryA with SDL2_mixer.dll ptr is set calling LoadLibraryA with FreeImage.dll ptr is NULL C:\Users\Admin\Documents\GitHub\Delivery\apps\00_03_freeimage_debug>dir 03/22/2023 01:45 PM 3,116 app.d 03/22/2023 01:46 PM 681,984 app.exe 03/06/2023 04:25 PM 3,805,184 assimp.dll 03/06/2023 04:25 PM 1,721,344 fmod.dll 03/06/2023 04:25 PM 6,942,208 FreeImage.dll 03/06/2023 04:25 PM 832,512 freetype.dll 03/06/2023 04:25 PM 216,576 glfw3.dll 03/06/2023 04:25 PM 122,904 OpenAL32.dll 03/06/2023 04:25 PM 1,220,096 SDL2.dll 03/06/2023 04:25 PM 143,872 SDL2_mixer.dll
My tiny program still can't get FreeImage.dll to load... GLFW.dll library loads no problem...
I appreciate all the help people have given me previously. So I've made everything super simple. The dub.sdl file consists of four lines: name "00_03_freeimage_debug" dependency "bindbc-glfw" version="~>1.0.0" dependency "bindbc-freeimage" version="~>1.0.2" versions "FI_318" The app.d use exists() functions to prove the existence of both .dll files before their load_xxx functions. import std.stdio; import std.file; // exists import bindbc.freeimage; import bindbc.loader; import bindbc.glfw; void main() { if (exists("FreeImage.dll")) writeln("the file FreeImage.dll DOES exist"); else writeln("the file FreeImage.dll NOT FOUND"); FISupport ret = loadFreeImage(`FreeImage.dll`); writeln("ret = ", ret); ret = loadFreeImage(); writeln("ret = ", ret); if (exists("glfw3.dll")) writeln("the file glfw3.dll DOES exist"); else writeln("the file glfw3.dll NOT FOUND"); GLFWSupport retGLFW = loadGLFW("glfw3.dll"); writeln("retGLFW = ", retGLFW); retGLFW = loadGLFW(); writeln("retGLFW = ", retGLFW); } The Output shows: the file FreeImage.dll DOES exist ret = noLibrary ret = noLibrary the file glfw3.dll DOES exist retGLFW = glfw30 retGLFW = glfw30 So my app.d thinks that FreeImage.dll is present. But loadloadFreeImage fails. My dub command uses the --arch=x86_64 so I know app.d is a 64 bit app. And I've checked the FreeImage.dll and downloaded it countless times making extra sure that it is the 64 bit Freeimage library and not the 32 bits. I'm getting the FreeImage.dll from SourceForge if that is relevant. My windows 10 machine shows FreeImage.dll to be the following: 07/31/2018 01:23 PM 6,942,208 FreeImage.dll 03/06/2023 04:25 PM 216,576 glfw3.dll I'm stuck. Not sure how to make any headway.
Re: dub.sdl bindbc-glfw is returning a deprecation warming. So what do I do now?
On Thursday, 9 March 2023 at 06:36:18 UTC, IchorDev wrote: On Thursday, 9 March 2023 at 00:21:02 UTC, WhatMeWorry wrote: [...] Sorry about that. Try updating to bindbc-glfw 1.0.2, should be fixed now. If you see any other deprecation warnings from BindBC bindings you can silence them with `-d` until they're updated. No problem :) Thanks!
dub.sdl bindbc-glfw is returning a deprecation warming. So what do I do now?
my small dub.sdl project uses: dependency "bindbc-glfw" version="~>1.0.1" versions "GLFW_33" and returns Building bindbc-glfw 1.0.1: building configuration [dynamic] C:\Users\Admin\AppData\Local\dub\packages\bindbc-glfw-1.0.1\bindbc-glfw\source\bindbc\glfw\binddynamic.d(557,11): Deprecation: variable `bindbc.loader.system.bindWindows` is deprecated So now what? I'm pretty sure deprecation means to replace with something better but what would that be? I looked on github code in binddynamic.d at line 557 and the package info at the DUB web site and I'm still clueless.
Re: Can't load FreeImage.dll with Windows
On Friday, 3 March 2023 at 19:44:17 UTC, ryuukk_ wrote: What happens if you put the dll next to your executable, does it find it? Good idea. I copied the dll into same directory as the executable and changed loadFreeImage to immutable FISupport fiLib = loadFreeImage(); And I get the same noLibrary result.
Can't load FreeImage.dll with Windows
I've tried distilling the problem to its very essence. I downloaded the FreeImage.dll from https://freeimage.sourceforge.io/download.html to the following directory: where /R c:\ FreeImage.dll c:\Users\Admin\Downloads\FreeImage3180Win32Win64\FreeImage\Dist\x64\FreeImage.dll dir c:\Users\Admin\Downloads\FreeImage3180Win32Win64\FreeImage\Dist\x64\FreeImage.dll 07/31/2018 12:23 PM 6,942,208 FreeImage.dll 1 File(s) 6,942,208 bytes dependency "bindbc-freeimage" version="~>1.0.0" versions "FI_318" but when I try to load the dll with the bindbc-freeimage package provided loadFreeImage function, all I get is no library found: writeln("The dub.sdl file of this project expects FreeImage version ", fiSupport); immutable FISupport fiLib = loadFreeImage("c:\\Users\\Admin\\Downloads\\FreeImage3180Win32Win64\\FreeImage\\Dist\\x64\\FreeImage.dll"); writeln("loadFreeImage returned: ", fiLib); OUTPUT --- The dub.sdl file of this project expects FreeImage version fi318 loadFreeImage returned: noLibrary I also tried: loadFreeImage(`c:\Users\Admin\Downloads\FreeImage3180Win32Win64\FreeImage\Dist\x64\FreeImage.dll`); and loadFreeImage(`c:/Users/Admin/Downloads/FreeImage3180Win32Win64/FreeImage/Dist/x64/FreeImage.dll`); but got same results. Also tried version="~>1.0.2"
Re: Dub is not finding the dynamic link library MSVCR120.dll...
On Monday, 20 February 2023 at 01:04:25 UTC, Mike Parker wrote: Any error about a missing DLL is a run-time error that's unrelated to dub or the compiler. Normally, for end users, a missing MSVC runtime DLL means you have to install the MSVC Redistributable package. This version of the DLL you're missing is from MSVC 2013, so that's the version of the package you'd need. However, I wonder what's causing the problem in the first place. Do you have Visual Studio installed, or are you using the out-of-the-box libraries and linker that ship with DMD? Thanks for setting me straight. I'm trying to make D application that you can just download and start up. Hopefully with having to install D first or the DLL. I see that msvc120.dll is in the same directory as dmd.exe.and dub.exe.
Dub is not finding the dynamic link library MSVCR120.dll...
and is abending with an error saying exactly this. How do I specify the path to this library? Can I use one of the environment variables in sc.ini, one of the Windows env variables, or one of the dub options? Btw, I'm bypassing on purpose the official D installation.
Re: Can't seem to find the relevant documentation for dub.
On Monday, 31 October 2022 at 20:31:11 UTC, ryuukk_ wrote: On Monday, 31 October 2022 at 20:20:49 UTC, WhatMeWorry wrote: I've got a pretty straightforward SDL dub file dependency "bindbc-opengl"version="~>1.0.3" versions "GL_46" dependency "bindbc-glfw" version="~>1.0.1" versions "GLFW_33" dependency "gl3n" version="~>1.4.1" dependency "bindbc-freeimage" version="~>0.1.1" versions "FI_317" Unresolvable dependencies to package bindbc-loader: bindbc-freeimage 0.1.1 depends on bindbc-loader ~>0.2.1 bindbc-freeimage 0.1.1 depends on bindbc-loader ~>0.2.1 bindbc-glfw 1.0.1 depends on bindbc-loader ~>1.0.0 bindbc-glfw 1.0.1 depends on bindbc-loader ~>1.0.0 bindbc-opengl 1.0.3 depends on bindbc-loader ~>1.0.0 ..\duball.exe exited with code 2 How to I tell dub that I want some packages to use different versions of the same package, bindbc-loader, in this case? You are using a very old version of freeimage, i suggest upgrading to the the latest one: 1.0.2 - https://code.dlang.org/packages/bindbc-freeimage Thank you. Specifying the newest freeimage package solved the problem. But now bindbc-assimp wants an older version of bindbc-loader but bindbc-assimp is at the most recent version. So is there a way to specify bindbc-loader ~>0.2.1 just for bindbc-assimp? Unresolvable dependencies to package bindbc-loader: bindbc-assimp 0.0.1 depends on bindbc-loader ~>0.2.1 bindbc-freeimage 1.0.2 depends on bindbc-loader ~>1.0.0 bindbc-glfw 1.0.1 depends on bindbc-loader ~>1.0.0 bindbc-opengl 1.0.3 depends on bindbc-loader ~>1.0.0 ..\duball.exe exited with code 2
Can't seem to find the relevant documentation for dub.
I've got a pretty straightforward SDL dub file dependency "bindbc-opengl"version="~>1.0.3" versions "GL_46" dependency "bindbc-glfw" version="~>1.0.1" versions "GLFW_33" dependency "gl3n" version="~>1.4.1" dependency "bindbc-freeimage" version="~>0.1.1" versions "FI_317" Unresolvable dependencies to package bindbc-loader: bindbc-freeimage 0.1.1 depends on bindbc-loader ~>0.2.1 bindbc-freeimage 0.1.1 depends on bindbc-loader ~>0.2.1 bindbc-glfw 1.0.1 depends on bindbc-loader ~>1.0.0 bindbc-glfw 1.0.1 depends on bindbc-loader ~>1.0.0 bindbc-opengl 1.0.3 depends on bindbc-loader ~>1.0.0 ..\duball.exe exited with code 2 How to I tell dub that I want some packages to use different versions of the same package, bindbc-loader, in this case?
Re: auto scope question?
typeof(screen.output.findSplit("")) s; Perfect. That was the "essence" of my question. But thanks to Ali, I don't have to use such esoteric syntax. D is a wonderful language, but I seem to shoot myself in the foot :)
auto scope question?
I'm naturally getting a undefined identifier `s` error in the return. Is there some way to refactor my code? I tried to declare s outside of the else brackets like: auto screen = executeShell(cmdLine); auto s; ... { s = screen.output.findSplit("REG_SZ"); } but that doesn't compile either. string[] getPath(string cmdLine) { auto screen = executeShell(cmdLine); if (screen.status != 0) { writeln(cmdLine, " failed"); } else { writeln("screen.output = ", screen.output); auto s = screen.output.findSplit("REG_SZ"); writeln("s[0] = ", s[0]); writeln("s[1] = ", s[1]); writeln("s[2] = ", s[2]); } return (s.split(';')); // Error: undefined identifier `s` }
Real simple question... for good programmers
string[] tokens = userSID.output.split!isWhite; writeln("tokens = ", tokens); tokens = ["SID", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "S-1-5-21-3823976785-3597194045-4221507747-1779", "", "", "", "", "", "", "", ""] Is there a clever way that I can discard all the extra null strings in the resultant string array? I've been playing with isControl, whitespace, etc. Ready to rip my hair out.
Can someone tell me what the compiler thought I was trying to do?
I lost about a half an hour troubleshooting some code of mine which as it turned out to be resolved with just one line. // paths.remove(i); // compiles fine but does nothing paths = paths.remove(i); // works - what I erroneously thought the previous line was doing Is the first line nonsensical and should the compiler have at least issued a warning?
probably a trivial question...
I was a little (nicely) surprised that I could use double quotes, single quotes, or back ticks in the following line of code. return s.split(";"); // double quotes or return s.split(';'); // single quotes or return s.split(`;`); // back ticks Does D provide any guidance as to what is preferred or are they identical for all intents and purposes?
Beginner memory question.
I'm playing around with dynamic arrays and I wrote the tiny program (at bottom). I get the following output: PS C:\D\sandbox> dmd -m64 maxMem.d PS C:\D\sandbox> .\maxMem.exe Reserving 1,610,613,245 elements reserve() returned a size of: 1,610,613,245 The capacity() of big is 1,610,613,245 ulong.sizeof (num bytes) = 8 Total bytes allocated = 12,884,905,960 Total megabytes allocated = 12,288 Total gigabytes allocated = 12 The discrepancy occurs because my Windows 10 computer only has 8.0 GB of memory (and that is not even taking the OS into consideration). Are my mega and giga sizes wrong? Is virtual memory entering into the equation? import std.stdio, std.array, std.algorithm; import std.format; import core.exception; void main() { ulong[] big; // reserve returns the new capacity of the array ulong e = 1_610_613_245; // 1_610_613_246 returns out of memory error writeln("Reserving ", format("%,3d", e) ," elements"); auto u = big.reserve(e); writeln("reserve() returned a size of: ", format("%,3d", u) ); writeln("The capacity() of big is ", format("%,3d", big.capacity)); writeln("ulong.sizeof (num bytes) = ", ulong.sizeof); writeln("Total bytes allocated = ", format("%,3d", e * ulong.sizeof)); immutable ulong megabyte = 1_048_576;// (1024 x 1024) immutable ulong gigabyte = 1024 * 1024 * 1024; writeln("Total megabytes allocated = ", format("%,3d", (e * ulong.sizeof)/megabyte)); writeln("Total gigabytes allocated = ", format("%,3d", (e * ulong.sizeof)/gigabyte)); }
Good to the last drop.
I run the program (at the bottom) and get, as expected, the run-time out of memory error: PS C:\D\sandbox> .\Reserve.exe newCapacity = [ 1] newCapacity = [ 3] newCapacity = [ 5] ooo newCapacity = [905,207,293] newCapacity = [905,207,805] newCapacity = [905,208,317] core.exception.OutOfMemoryError@src\core\lifetime.d(126): Memory allocation failed Is there a way to programmatically determine the exact maximum memory size available to the DRuntime’s array implementation? import std.stdio; import std.format; void main() { ulong[] big; size_t newCapacity; size_t oldCapacity; foreach(i; 0..ulong.max) { newCapacity = big.reserve(i); if(oldCapacity != newCapacity) { writeln(" newCapacity = ", format("[%15,3d]", newCapacity) ); oldCapacity = newCapacity; } } }
Basic question about size_t and ulong
Quoting the D documentation: size_t is an alias to one of the unsigned integral basic types, and represents a type that is large enough to represent an offset into all addressable memory. And I have a line of code: size_t huge = ulong.max; dmd GC.d GC.d(29): Error: cannot implicitly convert expression `18446744073709551615LU` of type 'ulong` to `uint Isn't ulong an integer? And isn't memory addresses 64 bits long? size_t huge = uint.max; // compiles works but now I'm just curious. I was just seeing what is the largest dynamic array I could create.
Embarrassed to ask this question because it seems so trivial but genuinely curious...
While studying Ali's book at chapter "Constructor and Other Special Functions" and the below code snippet: import std.stdio; struct S { this(int i) { writeln("an object"); } // Original //this(int i) const { writeln("a const object"); } //this(int i) immutable { writeln("an immutable object"); } //this(int i) shared { writeln("a shared object"); } const this(int i) { writeln("a const object"); } immutable this(int i) { writeln("an immutable object"); } shared this(int i) { writeln("a shared object"); } } void main() { auto m = S(1); auto c = const(S)(2); auto i = immutable(S)(3); auto s = shared(S)(4); } Assuming I can speak in correct programmer-ese: I was wondering why the qualifiers were placed after the function parameter list (int i). Just for fun, I moved to type qualifiers before the function definitions "this" (like a return type?) and the output was exactly identical. So I guess my question is, is this just a matter of esthetics or is some more nuanced goal at work here?
Re: Name mangling problem with tiny Windows 10 load-time DLL example
On Sunday, 28 February 2021 at 22:10:21 UTC, Siemargl wrote: On Sunday, 28 February 2021 at 18:29:11 UTC, WhatMeWorry wrote: It seems pretty obvious the problem is with name mangling. But how to fix it? fixing int numb = 1; and your example work correct ldc 1.24 / win10 P.S.I'm not recommend using such keywords as 'file', may cross with other modules. I double checked my posting and of course works it now works!?!? I've been having trouble where it works and then it doesn't. I've been using examples with file.d, file1.d, file2.d, etc. I also came across the note that Windows file system is not case sensitive. Or is that case in-sensitive? This worked fine for Linux (Ubuntu) so you might be on to something.
Name mangling problem with tiny Windows 10 load-time DLL example
It seems pretty obvious the problem is with name mangling. But how to fix it? -- module file; extern(D) export { int addOne(int i) { return (i + 1); } } -- module patron; import file; void main() { import std.stdio; int n = 1; writeln("mangled name of addOne is ", addOne.mangleof); numb = addOne(numb); } -- ldc2 -m64 -c file.d ldc2 -m64 -c patron.d ldc2 -m64 -shared file.obj -ofloadTime.dll Creating library loadTime.lib and object loadTime.exp Both dumpbin /exports loadTime.lib and dumpbin /exports loadTime.dll shows: _D4file6addOneFiZi ldc2 patron.obj loadTime.lib patron.exe mangled name of addOne is _D6patron6addOneFiZi // and library function is never called. Does not abend though??? --- So the library function is named _D4file6addOneFiZi while the user wants to call _D6patron6addOneFiZi So which name is "correct" and how do I get them to agree with each other?
Re: Real simple unresolved external symbols question...
On Wednesday, 10 February 2021 at 11:38:00 UTC, Ferhat Kurtulmuş wrote: On Tuesday, 9 February 2021 at 19:37:17 UTC, WhatMeWorry wrote: I'm trying to create a super simple dynamic library consisting of two files: [...] remove /NOENTRY, and include "mixin SimpleDllMain;" in one of the sources. And link with druntime. link /DLL file2.obj fileB.obj druntime-ldc.lib msvcrt.lib Okay, thanks. Then why does the README.md at https://github.com/dlang/druntime say "Runtime is typically linked together with Phobos in a release such that the compiler only has to link to a single library to provide the user with the runtime and the standard library."
Real simple unresolved external symbols question...
I'm trying to create a super simple dynamic library consisting of two files: file2.d -- extern(D): double addEight(double d) { return (d + 8.0); } fileB.d -- extern(D) { string concatSuffix(string s) { return (s ~ ".ext"); } } dmd -m64 -c file2.d dmd -m64 -c fileB.d creates file2.obj and fileB.obj files link.exe /DLL /NOENTRY file2.obj fileB.obj msvcrt.lib fileB.obj : error LNK2019: unresolved external symbol _D12TypeInfo_Aya6__initZ referenced in function _D5fileB12concatPrefixFAyaZQe fileB.obj : error LNK2019: unresolved external symbol _d_arraycatT referenced in function _D5fileB12concatPrefixFAyaZQe Ok. I find _d_arraycatT in the D website at: https://dlang.org/library/rt/lifetime/_d_arraycat_t.html So I thought, this symbol will be in phobos64.lib. But when I add it to the command, all hell breaks loose: link.exe /DLL /NOENTRY file2.obj fileB.obj msvcrt.lib phobos64.lib phobos64.lib(bits_23fa_21c.obj) : error LNK2001: unresolved external symbol memcpy o o o file2.dll : fatal error LNK1120: 57 unresolved externals So I'm stuck and don't have a clue as to how to continue. I thought Phobos64.lib was self-contained. Do I need to add other libraries? And how do I know which ones?
What is the difference between static linking with .a and .so libphobos?
I'm studying the D article at: https://dlang.org/articles/dll-linux.html#dso5 https://dlang.org/articles/dll-linux.html#dso6 Statically Linking D Program With libphobos2.a Statically Linking D Program With libphobos2.so Don't we want to Dynamically link with shared libphobos2.so? Also why doesn't Windows have a libphobos.dll file. I only find a libphobos.lib
What does this code snippet even do?
// The following four lines in run.lang.io int[] a; alias T = long; pragma(msg, is(typeof(a) : U[], U : T)); pragma(msg, is(typeof(a) : T[])); // returns true false But I'm not even sure what I'm looking at. Ali's book talks about the colon appearing for :, associative array ⬁ :, import ⬁ :, inheritance ⬁ :, label but I'm pretty sure none apply here. I know about alias (T is replaced with long), pragma, is, and typeof. But what is U and where does it come from? And what do the colons do here?
real beginner question about D's web site?
https://github.com/dlang/dlang.org/blob/ff235feedcb2bcb73ba348dcd1763542a43c7778/doc.ddoc D_S = $(LAYOUT ,$1,$(ARGS $+)) SPEC_S = $(LAYOUT ,$1,$(ARGS $+)) COMMUNITY= $(LAYOUT ,$1,$(ARGS $+)) _= LAYOUT=$3 _= I realize that D_S and LAYOUT, etc are macros. I've read the DDoc documentation and HTML, CSS, etc. but none of my research mentions the $ signs, as well as the $1 and $3. Am I missing something obvious?
Re: D static library on Windows 64 problem
On Sunday, 3 January 2021 at 15:49:03 UTC, Imperatorn wrote: On Saturday, 2 January 2021 at 22:08:34 UTC, WhatMeWorry wrote: On Saturday, 2 January 2021 at 22:04:28 UTC, WhatMeWorry wrote: I'm stepping through the windows static library tutorial at http://prowiki.org/wiki4d/wiki.cgi?D__Tutorial/CompilingLinkingD#Linkingmanually [...] Oops. used the manual example. Should be /LIBPATH:c:\dev\LibraryStudy\StaticLibrary\libfoobar If it doesn't say so on the wiki (haven't read), could you update it with your findings? Thanks! I'm sorry. The correction was for my first post, not the tutorial. If the tutorial was written for 64 bits I wouldn't be having this problem :)
Re: D static library on Windows 64 problem
On Saturday, 2 January 2021 at 22:04:28 UTC, WhatMeWorry wrote: I'm stepping through the windows static library tutorial at http://prowiki.org/wiki4d/wiki.cgi?D__Tutorial/CompilingLinkingD#Linkingmanually [...] Oops. used the manual example. Should be /LIBPATH:c:\dev\LibraryStudy\StaticLibrary\libfoobar
D static library on Windows 64 problem
I'm stepping through the windows static library tutorial at http://prowiki.org/wiki4d/wiki.cgi?D__Tutorial/CompilingLinkingD#Linkingmanually ``` The fix is to specify the prebuilt .lib file on the command line: dmd driver.d %cd%\libs\libfoo\libfoo.lib ``` The tutorial is for 32 bit so it uses OPTLINK. I'm using 64 bits so it uses Microsoft's link.exe When I try dmd -m64 -v driver.d -L=/LIBPATH:"c:\dev\LibraryStudy\StaticLibrary\libfoobar" I get this monstrosity link.exe /NOLOGO "driver.obj" /DEFAULTLIB:phobos64 /LIBPATH:"c:\dev\LibraryStudy\StaticLibrary\libfoobar" /OPT:NOICF /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\lib\x64" legacy_stdio_definitions.lib /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x64" which I think would work except for the fact the path argument looses its double quotes. Is there a fix? I tried invoking link.exe directly with the ""s added manually, but then link.exe complains that phobos64.lib can't be found.
Re: Simple clarification with "Building Libraries" online documentation
On Wednesday, 16 December 2020 at 22:51:55 UTC, WhatMeWorry wrote: Looking at; https://dlang.org/dmd-windows.html#library Compile modules separately and then run the librarian on them: dmd -c foo.d dmd -c bar.d phobos.lib -c -p32 foo.lib foo.obj bar.obj abc.obj def.lib My bad. I now see that the last two lines should have been concatenated into one dmd -c bar.d phobos.lib -c -p32 foo.lib foo.obj bar.obj abc.obj def.lib
Simple clarification with "Building Libraries" online documentation
Looking at; https://dlang.org/dmd-windows.html#library Compile modules separately and then run the librarian on them: dmd -c foo.d dmd -c bar.d phobos.lib -c -p32 foo.lib foo.obj bar.obj abc.obj def.lib The last line puzzles me. I presume phobos.lib is the "librarian" referred to in the first line, but where is it located? C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>phobos.lib 'phobos.lib' is not recognized as an internal or external command, operable program or batch file. I can find dmd, no problem: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>where dmd C:\D\dmd2\windows\bin\dmd.exe I see the lib.exe which I thought was the "librarian", but no phobos.lib? dir C:\D\dmd2\windows\bin Volume in drive C is Windows Volume Serial Number is B4B2-5727 Directory of C:\D\dmd2\windows\bin 04/04/2019 11:43 AM . 04/04/2019 11:43 AM .. 03/01/2019 10:56 PM 674,332 ddemangle.exe 03/01/2019 10:28 PM85,776 dm.dll 03/01/2019 10:50 PM 3,805,724 dmd.exe 03/01/2019 10:59 PM10,507,856 dub.exe 03/01/2019 10:57 PM 1,139,228 dustmite.exe 03/01/2019 10:28 PM 150,288 eecxxx86.dll 03/01/2019 10:28 PM80,656 emx86.dll 03/01/2019 10:28 PM72,776 lib.exe 03/01/2019 10:28 PM 523,278 libcurl.dll 03/01/2019 10:28 PM 223,260 link.exe 03/01/2019 10:28 PM14,048,768 lld-link.exe 03/01/2019 10:28 PM56,904 make.exe 03/01/2019 10:28 PM 275,216 mspdb41.dll 03/01/2019 10:28 PM 223,260 optlink.exe 03/01/2019 10:56 PM 1,015,324 rdmd.exe 03/01/2019 10:26 PM 963 README.TXT 03/01/2019 10:28 PM39,976 replace.exe 09/29/2020 01:51 PM 813 sc.ini 03/01/2019 10:28 PM57,616 shcv.dll 03/01/2019 10:28 PM67,144 shell.exe 03/01/2019 10:28 PM 8,976 tlloc.dll 03/01/2019 10:28 PM 567,096 windbg.exe 03/01/2019 10:28 PM 215,274 windbg.hlp 23 File(s) 33,840,504 bytes 2 Dir(s) 386,924,527,616 bytes free
Re: Anybody know if I can build DMD with Visual Studio 2019?
On Tuesday, 1 December 2020 at 22:58:53 UTC, WhatMeWorry wrote: I'm trying to build DMD with Visual D under Visual Studio as shown in the Wiki: https://wiki.dlang.org/Building_under_Windows The notes say to use the solution vcbuild: You should be able to build DMD using the visual studio solution found in: dmd\src\vcbuild A typical choice is to build the 64-bit debug version (the VisualD options are named 'Release' and 'x64'). [Btw, Should that be "64-bit release version" or "'Debug' and 'x64'"?] I do this with Visual Studio 2019 and I'm getting errors. Should I be using Visual Studio 2017 or even VS 2013? Didn't want to waste time debugging if VS2019 is not supported. It works now. Not sure what I did to _not_ make it work yesterday.
Anybody know if I can build DMD with Visual Studio 2019?
I'm trying to build DMD with Visual D under Visual Studio as shown in the Wiki: https://wiki.dlang.org/Building_under_Windows The notes say to use the solution vcbuild: You should be able to build DMD using the visual studio solution found in: dmd\src\vcbuild A typical choice is to build the 64-bit debug version (the VisualD options are named 'Release' and 'x64'). [Btw, Should that be "64-bit release version" or "'Debug' and 'x64'"?] I do this with Visual Studio 2019 and I'm getting errors. Should I be using Visual Studio 2017 or even VS 2013? Didn't want to waste time debugging if VS2019 is not supported.
DMD -i option, simple question...
The DMD forum mentions internal design. This is more of a beginner usage question. - from Compiler Switches - -I=directory Look for imports also in directory -i[=pattern ] Enables "include imports" mode, where the compiler will include imported modules in the compilation, as if they were given on the command line. By default, when this option is enabled, all imported modules are included except those in druntime/phobos The "..when this option is enabled..." is exactly the behavior I want, but how is it enabled? Is there an "all inclusive pattern" that I'm missing.
.d files without a module statement? Required to be absent?
I was poking around the dmd code just to "learn from the best" and I came across some files that ended with the .d extension which did not have the module statement. (I was under the naive impression that all .d files must have a module statement) However, in the directory: https://github.com/dlang/dmd/blob/master/samples I can see many examples where this is not the case. Most of them have things like Windows or C structures or calls, etc. In stark difference, there is https://github.com/dlang/dmd/tree/master/src/dmd/backend where all its files seem to have file name = module name strictly enforced. So I guess my question is when is the module statement required? Are they recommended but not essential? Maybe some "Best Practices" notation? the spec sasy "Modules automatically provide a namespace scope for their contents..." so maybe my question becomes, when are namespace scopes required to be present or required to be absent?
Re: question as to when a new command gets executed
On Wednesday, 11 November 2020 at 06:21:38 UTC, Jacob Carlborg wrote: On 2020-11-11 06:29, WhatMeWorry wrote: Which begs the question, how would the statement, m_State = new BreakState() ever get executed? class DebuggerSession { private BreakState m_State = new BreakState(); private UnrealCallback m_UnrealCallback; this( ) { } // rest of class } It gets executed at compile time. All instances of `DebuggerSession` will share the same single instance of `BreakState`. Thanks. Would you or anyone reading this know if this is unique to D or does C++ also behave like this? Also, where is the memory, that new allocates? Is it in the heap (thought heap was available only at runtime) or some other place? (Certainly not the stack, right?)
question as to when a new command gets executed
I've been studying an 8 year old D project in Github and this code fragment has left me befuddled. I'm confused as to when and how the new BreakState() statement gets executed. Wouldn't the class DebuggerSession need to be instantiated first and then the this() constructor be called? Which begs the question, how would the statement, m_State = new BreakState() ever get executed? class DebuggerSession { private BreakState m_State = new BreakState(); private UnrealCallback m_UnrealCallback; this( ) { } // rest of class }
D function in a .d file calling printf refuses to link.
module mydll; extern (C): import core.stdc.stdio : printf; export { int addSeven(int a, int b) { //printf("Hello from within my DLL"); return a+b+7; } } The above D code file compiles and links, no problems with C:\D\dmd2\samples\d\mydll>dmd -v -m64 mydll.d -L/DLL -L/NOENTRY But as soon as I uncomment the printf, all hell breaks loose with legacy_stdio_definitions.lib(legacy_stdio_definitions.obj) : error LNK2019: unresolved external symbol __acrt_iob_func referenced in function _vwprintf_l legacy_stdio_definitions.lib(legacy_stdio_definitions.obj) : error LNK2019: unresolved external symbol __stdio_common_vfwprintf referenced in function _vfwprintf_l legacy_stdio_definitions.lib(legacy_stdio_definitions.obj) : error LNK2019: unresolved external symbol __stdio_common_vfwprintf_s referenced in function _vfwprintf_s_l o o o Walter Bright even wrote a three line module at https://github.com/dlang/dmd/blob/master/samples/mydll/mydll.d which uses the printf.
Re: why do i need an extern(C): here?
On Friday, 16 October 2020 at 15:14:03 UTC, Ali Çehreli wrote: On 10/15/20 2:42 PM, Ali Çehreli wrote: > I've recently done the same by calling dlopen() and dlsym() > directly. Runtime.loadLibrary documentation says "If the library > contains a D runtime it will be integrated with the current runtime." > That would explain why my program seg-faults for my first tester with > the garbage collector signatures in the function call stack. Replacing dlopen() with Runtime.loadLibrary() did solve the segfault issue for me. Ali Isn't dlopen() for Linux and LoadLibrary() for Windows? Or are you running Windows Subsystem for Linus (WSL) or mingw? Just to add to the above discussions (for future searchers). I also found a demangle() in std.demangle that I used in the example below. alias addSevenFuncSignature = int function(int, int); addSevenFuncSignature addSeven; writeln(addSeven.mangleof); writeln(demangle(addSeven.mangleof)); _D9onlineapp4mainFZ8addSevenPFiiZi int function(int, int)* onlineapp.main().addSeven
why do i need an extern(C): here?
I've go a small DLL and a test module both written in D. Why do I need to use the extern(C)? Shouldn't both sides be using D name wrangling? mydll.d module mydll; extern(C): // removing or changing to (D): results in error export { int addSeven(int a, int b) { return a+b+7; } } user.d module user; import core.sys.windows.winbase; import std.stdio; void main() { alias addSevenFuncSignature = int function(int, int); addSevenFuncSignature addSeven; import core.runtime; auto mydll = Runtime.loadLibrary("mydll.dll"); assert(mydll); addSeven = cast(addSevenFuncSignature) GetProcAddress(mydll, "addSeven"); int ret = addSeven(2,3); writeln("calling addSeven(2,3) = ", addSeven(2,3)); Runtime.unloadLibrary(mydll); } --- execution results -- c:\D\dmd2\samples\d\mydll>dmd -m64 mydll.d -L/DLL -L/NOENTRY Creating library mydll.lib and object mydll.exp c:\D\dmd2\samples\d\mydll>dmd -m64 user.d c:\D\dmd2\samples\d\mydll>user.exe calling addSeven(2,3) = 12
Re: Trying to create a trivial 64 bit D Lang DLL on a Windows 10 machine and cant get past linking.
On Thursday, 1 October 2020 at 21:56:46 UTC, Ferhat Kurtulmuş wrote: On Thursday, 1 October 2020 at 21:35:42 UTC, WhatMeWorry wrote: On Thursday, 1 October 2020 at 20:28:58 UTC, kinke wrote: [...] Thanks all. I've gotten it to work with: [...] [...] [...] total = 12 [...] 1) try running your commands in Visual Studio Native x64 CMD. Yes, I've been doing that. 2) try link with msvcrt.lib The only msvcrt.lib I can find on my Windows 10 machine is: "C:\Windows Kits\10\Lib\10.0.19041.0\um\x64\ntstc_msvcrt.lib" Also on Microsoft's docs https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=vs-2019 it talks about a ucrt.lib?
Re: Trying to create a trivial 64 bit D Lang DLL on a Windows 10 machine and cant get past linking.
On Thursday, 1 October 2020 at 20:28:58 UTC, kinke wrote: On Thursday, 1 October 2020 at 20:03:19 UTC, WhatMeWorry wrote: Yes, but shouldn't the /NOENTRY option take care of that. Say, I just want to make a DLL of simple functions. Your little example has 2 problems, the first being an incompatible extern(D) ex/import (mydll.myAddSeven vs. user.myAddSeven) and the second being an incomplete/wrong linker cmdline. When changing the myAddSeven declarations to extern(C++) (another option being a mydll.di header for the import), it works with dmd -m64 -shared -L/NOENTRY mydll.d dmd -m64 user.d mydll.lib For more details, see also https://wiki.dlang.org/Win32_DLLs_in_D. Thanks all. I've gotten it to work with: dmd -m64 -ofmydll.dll mydll.d -L/NOENTRY -L/DLL dmd -m64 user.d mydll.lib user.exe total = 12 But then I got cocky and decided to just added a writeln() in the mydll.d file and I've been fighting this link error ever since: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\Hostx64\x64\link.exe /NOLOGO "mydll.obj" /OUT:"mydll.dll" /DEFAULTLIB:phobos64 /NOENTRY /DLL /OPT:NOICF /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\lib\x64" legacy_stdio_definitions.lib /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x64" Creating library mydll.lib and object mydll.exp mydll.obj : error LNK2019: unresolved external symbol fwrite referenced in function _D3std5stdio__T13trustedFwriteTaZQsFNbNiNePOS4core4stdcQBx6_iobufxAaZm phobos64.lib(object_72_81a.obj) : error LNK2001: unresolved external symbol memcpy phobos64.lib(exception_cf4_fff.obj) : error LNK2001: unresolved external symbol memcpy phobos64.lib(bits_23fa_21c.obj) : error LNK2001: unresolved external symbol memcpy phobos64.lib(gc_2413_a4e.obj) : error LNK2001: unresolved external symbol memcpy phobos64.lib(gc_2415_a03.obj) : error LNK2001: unresolved external symbol memcpy phobos64.lib(gc_2478_432.obj) : error LNK2001: unresolved external symbol memcpy o o o
Re: Trying to create a trivial 64 bit D Lang DLL on a Windows 10 machine and cant get past linking.
On Thursday, 1 October 2020 at 09:22:29 UTC, user1234 wrote: On Wednesday, 30 September 2020 at 11:45:53 UTC, Ferhat Kurtulmuş wrote: On Tuesday, 29 September 2020 at 21:22:21 UTC, WhatMeWorry wrote: module user; export { int myAddSeven(int a, int b); } [...] it is better to use this template https://github.com/dlang/dmd/tree/master/samples/mydll You don't have a DllMain. yeah that's the problem, check [0] OP. The author makes commercial dll on windows so he knows what he speaks about [0] https://forum.dlang.org/post/mscgsclxwtjcferfx...@forum.dlang.org Yes, but shouldn't the /NOENTRY option take care of that. Say, I just want to make a DLL of simple functions.
Trying to create a trivial 64 bit D Lang DLL on a Windows 10 machine and cant get past linking.
module user; export { int myAddSeven(int a, int b); } void main() { int total = myAddSeven(2, 3); } dmd -m64 -c user.d module mydll; export extern(D) { int myAddSeven(int a, int b) { return a+b+7; } /* <-- function body */ } dmd -c -shared -m64 mydll.d link mydll.obj /DLL /NOENTRY Microsoft (R) Incremental Linker Version 14.27.29111.0 Copyright (C) Microsoft Corporation. All rights reserved. Creating library mydll.lib and object mydll.exp link user.obj /implib:mydll.lib Microsoft (R) Incremental Linker Version 14.27.29111.0 Copyright (C) Microsoft Corporation. All rights reserved. LINK : fatal error LNK1104: cannot open file 'phobos64.lib' or when I give the linker phobos64.lib link user.obj /implib:mydll.lib /LIBPATH:C:\D\dmd2\windows\lib64 Microsoft (R) Incremental Linker Version 14.27.29111.0 Copyright (C) Microsoft Corporation. All rights reserved. user.obj : error LNK2019: unresolved external symbol __imp__D4user10myAddSevenFiiZi referenced in function _Dmain phobos64.lib(stacktrace_1be8_3e5.obj) : error LNK2019: unresolved external symbol snprintf referenced in function _D4core3sys7windows10stacktrace10StackTrace13resolveNoSyncFAxmZAAa phobos64.lib(demangle_c96_79b.obj) : error LNK2001: unresolved external symbol snprintf phobos64.lib(parseoptions_e2c_21b.obj) : error LNK2001: unresolved external symbol snprintf phobos64.lib(parseoptions_e2c_21b.obj) : error LNK2019: unresolved external symbol sscanf referenced in function _D4core8internal12parseoptions5parseFNbNiAxaKANgaKfQkZb user.exe : fatal error LNK1120: 3 unresolved externals
miscellaneous array questions...
1) The D Language Reference says: "There are four kinds of arrays..." with the first example being "type* Pointers to data" and "int* p; etc. At the risk of sounding overly nitpicky, isn't a pointer to an integer simply a pointer to an integer? How does that pertain to an array? 2) "The total size of a static array cannot exceed 16Mb" What limits this? And with modern systems of 16GB and 32GB, isn't 16Mb excessively small? (an aside: shouldn't that be 16MB in the reference instead of 16Mb? that is, Doesn't b = bits and B = bytes) 3) Lastly, In the following code snippet, is arrayA and arrayB both allocated on the stack? And how does their scopes and/or lifetimes differ? module1 = int[100] arrayA; void main() { int[100] arrayB; // ... } module1 =
Probably a trivial question regarding version identifier and unittest
I'm trying to study Adam Ruppe's terminal.d sub-package and I see the following code segment: version(demos) unittest { import arsd.terminal; void main() { // . . . } main; // exclude from docs } Looks like a good baby step to take, so in the command line I use: C:\dub\path\to\arsdpackage\arsd-official>dmd terminal.d -unittest -version=demos OPTLINK (R) for Win32 Release 8.00.17 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Warning 134: No Start Address Shouldn't the version identifier demos and the unittest option activate the test block and therefore defines main() which then give the "Start Address"? Also, what is the isolated main; command right after the main function?
What's the difference between sourcePaths and importPaths in DUB?
The documentation doesn't go into much detail: sourcePaths "" ["" [...]] Allows to customize the path where to look for source files (any folder "source" or "src" is automatically used as a source path if no sourcePaths setting is specified) - note that you usually also need to define "importPaths" as "sourcePaths" don't influence those
Re: arsd errors on windows
Really stupid question here, but when I try to run the same command I get: C:\Users\whatmeworry>dub add arsd-official Unknown command: add USAGE: dub [--version] [] [] [-- []] . . . DUB version 1.11.0, built on Oct 6 2018 I thought about dub init, but that still doesn't give me an 'add' command. Looking at help screen in Dub, I see add-path, add-local, etc. but the documentation says "dub add arsd-official".
Re: Difference between slice[] and slice
On Wednesday, 25 September 2019 at 19:25:06 UTC, Ali Çehreli wrote: On 09/25/2019 12:06 PM, WhatMeWorry wrote: > I was > assuming that [] meant "the entirety" of the array. Assuming we're talking about D slices, Yes. (It could be a user-defined type with surprisingly different semantics.) > In short, is there anytime that one would want to use "slice[] = > something" syntax?I That changes element values. Ok. But which element(s)? In my specific case, I was using []. Is waste[] = waste[0..$-1]; even semantically meaningful? Because the LDC compiler had no problem compiling it. > //waste[] = waste[0..$-1]; // object.Error@(0): Array lengths don't > match for copy: 0 != 1 > > waste = waste[0..$-1]; // works That makes slice refer to a different set of elements. In that example, the slice does not include the last element anymore. Ali
Difference between slice[] and slice
Just got through debugging a line of code which uses dynamic array. It boiled to to my use of []. How should I "D think" about slice[]? The run time error seems to say the the length of [] is zero. I was assuming that [] meant "the entirety" of the array. In short, is there anytime that one would want to use "slice[] = something" syntax?I //waste[] = waste[0..$-1]; // object.Error@(0): Array lengths don't match for copy: 0 != 1 waste = waste[0..$-1]; // works
Re: It there a way to get this to compile?
On Monday, 9 September 2019 at 19:12:34 UTC, Adam D. Ruppe wrote: On Monday, 9 September 2019 at 19:08:17 UTC, WhatMeWorry wrote: Is this even possible? what are you trying to do? if c is static, it just needs to be initialized by a helper function, like int helper() { int c = 60; foreach(f; foundations) c += 10; return c; } static int c = helper(); // it initializes based on teh function now Oops. I'm trying to build up a complex formatting string of Console Virtual Terminal Sequences. Should be ~= or is that =~. I never can remember. immutable string brackets ~= "\033[" ~ to!string(r) ~ ";" ~ to!string(c) ~ "H";
It there a way to get this to compile?
Is this even possible? klondike.d(155): Error: no identifier for declarator c klondike.d(155): Error: declaration expected, not = struct FoundationPile { Card[] up;// all cards are face up on the Foundation } FoundationPile[4] foundations; static if(true) { int r = 2; int c = 40; static foreach(i ; foundations) { immutable string brackets = "\033[" ~ to!string(r) ~ ";" ~ to!string(c) ~ "H"; c = c + 10; // line 155 } }
Quick question regarding dynamic array deletions
int[] a = [ 3, 7, 9 ]; 1) a = []; and 2) a = null; sets both the .ptr property of the array to null, and the length to 0. whereas 3) a.length = 0; just sets the length to 0. If all the above is correct, does this mean we should just stick to either of the first two forms and never use 3). Maybe my question is when would be want to use 3) without also adjusting the .ptr ?
How do I display unicode characters in D on standard (english) Windows 10 console window?
This is a very stupid question but from Ali's book, I took this segment: writeln("Résumé preparation: 10.25€"); writeln("\x52\ésum\u00e9 preparation: 10.25\€"); and after running it all I get is the following: R├⌐sum├⌐ preparation: 10.25Γé¼ R├⌐sum├⌐ preparation: 10.25Γé¼ I was expecting the symbol "£" or something like that. What am I missing?
I really don't understand DUB
I've been using DUB for several years and I've gotten it to work generally. But I've been trying to troubleshoot a DUB issue for two days now and I've come to the conclusion, I don't really understand DUB and I'm tired of muddling through. (Surely it hurts that I've never been exposed to a library or package manager in general) Now, I've studied the on-line documentation and even walked through the code somewhat but I'm not making an headway. Maybe a higher level approach is required. Is there some good beginner tutorial that I'm missing? Ideally, like a gentle walk through, for both Windows and POSIX?
Re: Get this error running the D blog about containerizing D in Docker
On Tuesday, 26 March 2019 at 21:20:06 UTC, Andre Pany wrote: On Tuesday, 26 March 2019 at 17:36:15 UTC, WhatMeWorry wrote: https://dlang.org/blog/2019/03/14/containerize-your-d-server-application/ I'm following the excellent blog posting by Mr. Nacke, but I keep getting the following error when I attempt to compile hellorest with dub. Since everything is pretty much on autopilot, Everything seems to have worked beautifully up to this step. [...] This error should not occur in recent versions of dub. Which dub version do you have (dub --version)? Kind regards Andre Thanks, I'm running Ubuntu 18.0. When I do a sudo apt-get install dub Reading package lists... Done Building dependency tree Reading state information... Done dub is already the newest version (1.8.0-2). 0 upgraded, 0 newly installed, 0 to remove and 151 not upgraded. but dub list returns 1.14.0 dub 1.14.0: /home/generic/.dub/packages/dub-1.14.0/dub/ Do I have two versions of dub? 1.8.0-2 and 1.14.0? Get the same error.
Get this error running the D blog about containerizing D in Docker
https://dlang.org/blog/2019/03/14/containerize-your-d-server-application/ I'm following the excellent blog posting by Mr. Nacke, but I keep getting the following error when I attempt to compile hellorest with dub. Since everything is pretty much on autopilot, Everything seems to have worked beautifully up to this step. generic@generic-M93p:~/vibed-docker$ dub --build=release --compiler=ldc2 --verbose Using dub registry url 'https://code.dlang.org/' Refreshing local packages (refresh existing: true)... Looking for local package map at /var/lib/dub/packages/local-packages.json Looking for local package map at /home/generic/.dub/packages/local-packages.json Determined package version using GIT: hellorest ~master Refreshing local packages (refresh existing: false)... Looking for local package map at /var/lib/dub/packages/local-packages.json Looking for local package map at /home/generic/.dub/packages/local-packages.json Found dependency vibe-d 0.8.5-rc.1 Found dependency vibe-d:redis 0.8.5-rc.1 Found dependency vibe-d:http 0.8.5-rc.1 o o o Search for versions of openssl (1 package suppliers) Return for openssl: [2.0.0+1.1.0h, 1.1.6+1.0.1g, 1.1.5+1.0.1g, 1.1.4+1.0.1g, 1.1.3+1.0.1g, 1.1.2+1.0.1g, 1.1.1+1.0.1g, 1.1.0+1.0.1g, 1.0.0+1.0.0e, ~master] Search for versions of botan (1 package suppliers) Ignoring version specification (>=0.0.0) for path based dependency ../memutils Return for botan: [1.12.10, 1.12.9, 1.12.8, 1.12.7, 1.12.6, 1.12.5, 1.12.4, 1.12.3, 1.12.2, 1.12.1, 1.12.0, 1.11.14, 1.11.13, 1.11.12, 1.11.11, 1.11.10, ~master, ~merge-new-algos, ~ldc-compat, ~fix-tls] Search for versions of botan-math (1 package suppliers) Return for botan-math: [1.0.3, 1.0.2, 1.0.1, 1.0.0, ~master] Sub package botan:base doesn't exist in botan 1.12.10. o o o Sub package botan:base doesn't exist in botan 1.11.10. Sub package botan:base doesn't exist in botan ~master. Sub package botan:base doesn't exist in botan ~merge-new-algos. Sub package botan:base doesn't exist in botan ~ldc-compat. Sub package botan:base doesn't exist in botan ~fix-tls. Sub package botan:compression doesn't exist in botan 1.12.10. o o o Sub package botan:compression doesn't exist in botan 1.11.10. Sub package botan:compression doesn't exist in botan ~master. Sub package botan:compression doesn't exist in botan ~merge-new-algos. Sub package botan:compression doesn't exist in botan ~ldc-compat. Sub package botan:compression doesn't exist in botan ~fix-tls. Sub package botan:tls doesn't exist in botan 1.12.10. o o o Sub package botan:tls doesn't exist in botan 1.11.10. Sub package botan:tls doesn't exist in botan ~master. Sub package botan:tls doesn't exist in botan ~merge-new-algos. Sub package botan:tls doesn't exist in botan ~ldc-compat. Sub package botan:tls doesn't exist in botan ~fix-tls. Sub package botan:passhash doesn't exist in botan 1.12.10. o o o Sub package botan:passhash doesn't exist in botan 1.11.10. Sub package botan:passhash doesn't exist in botan ~master. Sub package botan:passhash doesn't exist in botan ~merge-new-algos. Sub package botan:passhash doesn't exist in botan ~ldc-compat. Sub package botan:passhash doesn't exist in botan ~fix-tls. Failed to load path based dependency memutils: No package file found in ../memutils/, expected one of dub.json/dub.sdl/package.json Search for versions of mir-linux-kernel (1 package suppliers) Return for mir-linux-kernel: [1.0.1, 1.0.0, 1.0.0-alpha2, 1.0.0-alpha1, ~master] Search for versions of diet-ng (1 package suppliers) Return for diet-ng: [1.5.0, 1.4.5, 1.4.4, 1.4.3, 1.4.2, 1.4.1, 1.4.0, 1.3.0, 1.2.1, 1.2.0, 1.1.4, 1.1.3, 1.1.2, 1.1.1, 1.1.0, 1.0.0, 0.3.0, 0.2.1, 0.2.0, 0.1.0, 1.0.0-beta.3, 1.0.0-beta.2, 1.0.0-beta.1, 1.0.0-alpha.2, 1.0.0-alpha.1, ~master, ~dmd_segfault] The dependency resolution process is taking too long. The dependency graph is likely hitting a pathological case in the resolution algorithm. Please file a bug report at https://github.com/dlang/dub/issues and mention the package recipe that reproduces this error.
Re: C++ GLM(OpenGL Mathematics) D Equivalent.
On Tuesday, 4 September 2018 at 19:40:10 UTC, JN wrote: On Tuesday, 4 September 2018 at 19:23:16 UTC, SrMordred wrote: Most C++ game related projects uses GLM as they default math/vector lib (even if not using opengl). In D we have (that I found): gfm.math - https://github.com/d-gamedev-team/gfm dlib.math - https://github.com/gecko0307/dlib Gl3n - https://github.com/Dav1dde/gl3n But i'm not sure which to pick. Can someone point me out some reasons to use one over the other? (or show some differences) I´m expecting something of equivalent functions and performance as c++ glm. Thank you! I use dlib.math for my 3D engine. It's working fairly well, can't complain. No clue about gfm. Gl3n is nice, but it has a design flaw - it's using row-major matrix ordering. It may or may not be a big deal for you, but in general, it means that all matrices being sent to OpenGL need to be transposed, and the matrix multiplication order is reversed. Another advantage of dlib.math is that it has some extended features, such as support for calculating tangents for a mesh. I've used gl3n exclusively for years, but just call opengl functions with the "transpose" argument set to true. Or for readability, I define: alias ROW_MAJOR = GL_TRUE; glUniformMatrix4fv(glGetUniformLocation(this.ID, name), 1, ROW_MAJOR, &matrix[0][0]); However, in hindsight, I think gfm.math might be the way to go.
Re: why use string for this example of appender?
Thanks all. I sometimes feel like Michael Corleone: "Just when I thought I was out, they pull me back in!" :) I realize it is not the place for it, but sometimes I wish the Library Reference explained things in terms of "why".
Re: does the shared keyword work with mutable structs?
On Friday, 9 March 2018 at 10:42:47 UTC, Kagamin wrote: To make a struct noncopyable, add @disable this(this); to it, then compiler will give an error on an attempt to copy it. I tried the @disable this(this); but now it doesn't even compile? Error: template std.concurrency.spawn cannot deduce function from argument types !()(void function(shared(EventBuffer) eB, shared(Lock) lock), shared(EventBuffer), shared(Lock)), candidates are: C:\ldc2\bin\..\import\std\concurrency.d(464): std.concurrency.spawn(F, T...)(F fn, T args) if (isSpawnable!(F, T)) Is std.concurrency a work in progress or I'm I just obtuse here? I've been reading Ali's book on the concurrency chapters as inspiration, but the examples there use simple data types like ints or bools.
does the shared keyword work with mutable structs?
I read where shared classes have not been implemented yet. So I'm using just a struct e below: But the output below is showing that sharing is not happening between Struct in main() and the various spawned threads. I'm I doing something wrong? creating queue in EventBuffer constructor eventBuffer.enter = 1 eventBuffer.leave = 0 eB.enter = 0 eB.enter = 0 eB.leave = 0 eB.leave = 0 eB.enter = 0 eB.leave = 0 void producer(in ref shared(EventBuffer) eB, shared(Lock) lock) { writeln("eB.enter = ", eB.enter); writeln("eB.leave = ", eB.leave); Event event; foreach(i; 0..7) { synchronized(lock) { event.keyPressed = i; eB.enterOrLeaveQueue(Direction.Entering, event); } } } void main() { shared(Lock) lock = new shared(Lock)(); shared(EventBuffer) eventBuffer = EventBuffer(50); writeln("eventBuffer.enter = ", eventBuffer.enter); writeln("eventBuffer.leave = ", eventBuffer.leave); foreach(i; 0..3) { spawn(&producer, eventBuffer, lock); } }
Shouldn't D be added to this list?
Sorry if this is the wrong place to post, but I just came across this just now: https://www.khronos.org/opengl/wiki/Language_bindings I was thinking that with derelictGL, D should be on this list? If so, I'm not sure how one would go about this?
Re: How to move an associative array between modules?
On Thursday, 11 January 2018 at 23:29:30 UTC, Adam D. Ruppe wrote: On Thursday, 11 January 2018 at 23:20:44 UTC, WhatMeWorry wrote: When I simply move the array out of main() but still in app.d, the compiler returns Error: expression ["SCRATCH":Track("scratch.wav", cast(Sound)1, 0, null),... is not a constant. Can I use "static if" or "static this()", or "mixin" or some other technique? Yeah, just declare the array outside, then initialize it inside a static this() constructor. int[int] foo; static this() { foo = [1:1]; } I hate to keep being a bother, but my project with the below static this() now compiles fine, but aborts during runtime with a "a problem caused the program to stop working ..." Does static if have some pitfalls I'm unaware of? static this() { tracks["SCRATCH"] = Track("scratch.wav", Sound.SOUND_EFFECT, ONCE,null ); // or this form code segment Track[string] tracks = [ "SCRATCH" : Track("scratch.wav", Sound.SOUND_EFFECT, ONCE,null ) ]; } I even tried just foo = [1:1]; but that crashed during run time. I have a writeln() statement just after main() so I know it is occurring before main().
How to move an associative array between modules?
I've built a sound.d module with lots data types, free functions (initAndOpenSound() loadSound()), and enums etc. In my main/app.d module, I've created the the following associative array: void main(string[] argv) { initAndOpenSound(); Track[string] tracks = [ "SCRATCH" : Track("scratch.wav", Sound.SFX, ONCE,null ), "BACKGROUND_SOUND" : Track("beat.wav",Sound.MUSIC, FOREVER, null ), "HIGH" : Track("high.wav",Sound.SFX, ONCE,null ) ]; foreach(string s, Track t; tracks) { loadSound(t); // sets ptr to a file with audio data tracks[s] = t; // update associative array } Everything works. But I know in the future, that the tracks is going to get very large. So I want to get it out of main() and move it to the sound.d module. I've tried this but all hell breaks loose and I can't make just of the compiler errors When I simply move the array out of main() but still in app.d, the compiler returns Error: expression ["SCRATCH":Track("scratch.wav", cast(Sound)1, 0, null),... is not a constant. Can I use "static if" or "static this()", or "mixin" or some other technique? Or do I need to refactor my code completely?
Is there a way to get this associative array initialization to work?
enum SoundType { MUSIC = 0, SOUND_EFFECT }; struct Sound { string file; SoundType musicOrSfx; void* ptr; // Mix_Chunk* for sfx; Mix_Music* for music; } immutable Sound[string] soundLibrary = // line 148 [ "SCRATCH" : { file : "scratch.wav", musicOrSfx : SOUND_EFFECT, ptr : null }, "BACKGROUND_TRACK" : { file : "beat.wav",musicOrSfx : MUSIC,ptr : null }, "HIGH" : { file : "high.wav",musicOrSfx : SOUND_EFFECT, ptr : null } ]; I keep getting a source\app.d(148,1): Error: not an associative array initializer
How to I get the dub package version that I want...
I can compile the derelict-fmod example with dub.json ... "dependencies": { "derelict-util": ">=1.9.1" ... and dub.selections.json ... "versions": { "derelict-util": "2.1.0" ... dub run Fetching derelict-util 2.1.0 (getting selected version)... Performing "debug" build using ldc2 for x86_64. derelict-util 2.1.0: building configuration "library"... == In my project, I use SDL dub.sdl ... dependency "derelict-util" version=">=1.9.1" ... dub upgrade Upgrading project in /home/generic/Delivery/apps/06_03_09_audio Fetching derelict-util 2.0.6 (getting selected version)... which is a higher version but no cigar. So I try brute force with dub.sdl ... dependency "derelict-util" version="==2.1.0" ... but dub upgrade returns: Upgrading project in /home/generic/Delivery/apps/06_03_09_audio Root package 06_03_09_audio reference derelict-util 2.1.0 cannot be satisfied. There is definitely a 2.1.0 derelict-util package with a time stamp of 2016-Sep-05 So what am I doing wrong?
Dub project has both .sdl and .json files. Is this normal or did I do something wrong?
I've been using Dub for a while but from the very beginning I decided to go with SDL 100% of the time, So I've got a dub.sdl file like: name "01_10_camera_view_space" description "A minimal D application." authors "kheaser" copyright "Copyright © 2017, kheaser" license "proprietary" dependency "derelict-al" version="~>1.0.3" dependency "derelict-assimp3" version="~>1.3.0" dependency "derelict-fi" version="~>2.0.3" dependency "derelict-fmod"version="~>2.0.4" dependency "derelict-ft" version="~>1.1.3" dependency "derelict-gl3" version="~>1.0.23" dependency "derelict-glfw3" version="~>3.1.3" dependency "derelict-util"version="~>2.0.6" dependency "gl3n" version="~>1.3.1" . But when I look the directory that has the dub.sdl file, I also see a file called dub.selections.json { "fileVersion": 1, "versions": { "derelict-al": "1.0.3", "derelict-assimp3": "1.3.0", "derelict-fi": "2.0.3", "derelict-fmod": "2.0.4", "derelict-ft": "1.1.3", "derelict-gl3": "1.0.23", "derelict-glfw3": "3.1.3", "derelict-util": "2.0.6", "gl3n": "1.3.1" } } So how did this .json file get created and can I just delete it? I only noticed this because when I was troubleshooting the project, I changed the dub.sdl library versions but the compile/run was using the library versions in dub.selections.json. I did switch from using DMD to LDC, if that has any bearing.
Any derelict fmod users on Linux out there?
I've tried debugging this for hours to no avail. It works on Windows and Mac fine. But I'm running Antergos Linux (very much like Arch) and it keeps failing at the System Init line. The code is pretty much a copy of the example of derelict fmod on github. I have no idea what the "bindings" number below refers to? === Code snippet == auto res = FMOD_System_Create(&fmod); // works printVersion(); printDrivers(); FMOD_RESULT res2 = FMOD_System_Init(fmod, 32, FMOD_INIT_NORMAL, null); checkForErrors(res2, "After call to FMOD_System_Init", true); === Output = FMOD library loaded fmod version: 69633 (bindings: 67335) fmod drivers: 1 fmod driver [0]: (48000,3,2,'Built-in Audio Analog Stereo') i = 0 sampleRate = 48000 speakermode = 3 speakermodeChannels = 2 name = Built-in Audio Analog Stereo FMOD error An error occurred that wasn't supposed to. Contact support. My run time libraries consist of the very latest from the fmod web site. libfmod.so libfmod.so.10 libfmod.so.10.1 libmodstudio.so libmodstudio.so.10 libmodstudio.so.10.1
Infuriating DUB/DMD build bug.
I've got a github project and using DUB with DMD and I keep running into this problem. I've tried deleting the entire ...\AppData\Roaming\dub\packages folder, but the problem repeats the very next build attempt. Fetching derelict-util 2.0.6 (getting selected version)... Fetching derelict-ft 1.1.3 (getting selected version)... Fetching derelict-gl3 1.0.23 (getting selected version)... Fetching derelict-assimp3 1.3.0 (getting selected version)... Fetching gl3n 1.3.1 (getting selected version)... Fetching derelict-al 1.0.3 (getting selected version)... Fetching derelict-fmod 2.0.4 (getting selected version)... Fetching derelict-fi 2.0.3 (getting selected version)... Fetching derelict-glfw3 3.1.3 (getting selected version)... Performing "$DFLAGS" build using dmd for x86_64. derelict-util 2.0.6: building configuration "library"... derelict-al 1.0.3: building configuration "library"... derelict-assimp3 1.3.0: building configuration "library"... derelict-fi 2.0.3: building configuration "library"... derelict-fmod 2.0.4: building configuration "library"... derelict-ft 1.1.3: building configuration "library"... derelict-gl3 1.0.23: building configuration "library"... derelict-glfw3 3.1.3: building configuration "derelict-glfw3-dynamic"... Error: Error writing file '..\..\..\..\AppData\Roaming\dub\packages\derelict-glfw3-3.1.3\derelict-glfw3\.dub\build\derelict-glfw3-dynamic-$DFLAGS-windows-x86_64-dmd_2076-A09416BA47731198A57C73719DAAFE33\DerelictGLFW3.lib' dmd failed with exit code 1. I've cloned DMD and when I searched for "Error writing file" all it pulls up is: /** * Writes a file, terminate the program on error * * Params: * loc = The line number information from where the call originates * f = a `ddmd.root.file.File` handle to write */ extern (C++) void writeFile(Loc loc, File* f) { if (f.write()) { error(loc, "Error writing file '%s'", f.name.toChars()); fatal(); } } But shouldn't there be a line number before "Error writing file"? With writing files, that's usually a permissions thing? But all the other 8 packages build fine? Note: I had a similar problem with derelict-assimp3 package, so I went to an entirely different system and cloned my project. But now it fails with the same error, but with a different package.
Re: splitter string/char different behavior
On Saturday, 30 September 2017 at 18:21:11 UTC, Jon Degenhardt wrote: On Saturday, 30 September 2017 at 17:17:17 UTC, SrMordred wrote: [...] It's easy to overlook, but documentation for splitter starts out: Lazily splits a range using an element as a separator. An element of a string is a char, not a string. It needs to be read somewhat literally, but it is correct. It's also part of template constraint, useful once you've become accustomed to reading them: auto splitter(alias pred = "a == b", Range, Separator)(Range r, Separator s) if (is(typeof(binaryFun!pred(r.front, s)) : bool) && For "a.b.c"splitter(x), Range r is a string, r.front is a char. The template can only be instantiated if the predicate function is valid. The predicate function is "a == b". Since r.front is a char, then s must be a type that can be compared with '=='. A string and char cannot be compared with '==', which is why the a valid template instantiation could not be found. Would it be correct to just update the documentation to say "Lazily splits a range using an char as a separator" ? what is it; wchar and dchar too? I notice the example that is there has ' ' as the element.
This used to compile for months and months, and now it aborts with Error writing file derelict-assimp3-1.3.0
I don't know the first step about how to trouble shoot this? I haven't changed anything with my configuration. Using dub registry url 'http://code.dlang.org/' Refreshing local packages (refresh existing: true)... Looking for local package map at C:\ProgramData\dub\packages\local-packages.json Looking for local package map at C:\Users\kheaser\AppData\Roaming\dub\packages\local-packages.json Note: Failed to determine version of package 00_01_print_ogl_ver at .. Assuming ~master. Refreshing local packages (refresh existing: false)... Looking for local package map at C:\ProgramData\dub\packages\local-packages.json Looking for local package map at C:\Users\kheaser\AppData\Roaming\dub\packages\local-packages.json Found dependency derelict-util 2.0.6 Found dependency derelict-ft 1.1.3 Found dependency derelict-gl3 1.0.23 Found dependency derelict-assimp3 1.3.0 Found dependency derelict-al 1.0.3 Found dependency derelict-fmod 2.0.4 Found dependency derelict-fi 2.0.3 Found dependency derelict-glfw3 3.1.3 Refreshing local packages (refresh existing: false)... Looking for local package map at C:\ProgramData\dub\packages\local-packages.json Looking for local package map at C:\Users\kheaser\AppData\Roaming\dub\packages\local-packages.json Found dependency derelict-util 2.0.6 Found dependency derelict-ft 1.1.3 Found dependency derelict-gl3 1.0.23 Found dependency derelict-assimp3 1.3.0 Found dependency derelict-al 1.0.3 Found dependency derelict-fmod 2.0.4 Found dependency derelict-fi 2.0.3 Found dependency derelict-glfw3 3.1.3 Checking for upgrades. Using cached upgrade results... Generating using build Generate target 00_01_print_ogl_ver (executable C:\Users\kheaser\OneDrive for Business\GitHub\Delivery\apps\00_01_print_ogl_ver\bin 00_01_print_ogl_ver) Generate target derelict-al (staticLibrary C:\Users\kheaser\AppData\Roaming\dub\packages\derelict-al-1.0.3\derelict-al\lib DerelictAL) Generate target derelict-util (staticLibrary C:\Users\kheaser\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\lib DerelictUtil) Generate target derelict-assimp3 (staticLibrary C:\Users\kheaser\AppData\Roaming\dub\packages\derelict-assimp3-1.3.0\derelict-assimp3\lib DerelictASSIMP3) Generate target derelict-fi (staticLibrary C:\Users\kheaser\AppData\Roaming\dub\packages\derelict-fi-2.0.3\derelict-fi\lib DerelictFI) Generate target derelict-fmod (staticLibrary C:\Users\kheaser\AppData\Roaming\dub\packages\derelict-fmod-2.0.4\derelict-fmod\lib DerelictFmod) Generate target derelict-ft (staticLibrary C:\Users\kheaser\AppData\Roaming\dub\packages\derelict-ft-1.1.3\derelict-ft\lib DerelictFT) Generate target derelict-gl3 (staticLibrary C:\Users\kheaser\AppData\Roaming\dub\packages\derelict-gl3-1.0.23\derelict-gl3\lib DerelictGL3) Generate target derelict-glfw3 (staticLibrary C:\Users\kheaser\AppData\Roaming\dub\packages\derelict-glfw3-3.1.3\derelict-glfw3\lib DerelictGLFW3) Performing "$DFLAGS" build using dmd for x86_64. derelict-util 2.0.6: building configuration "library"... dmd -m64 -I..\ -I..\common -I..\common_game -lib -of..\..\..\..\..\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\.dub\build\library-$DFLAGS-windows-x86_64-dmd_2075-288F079949563AF9CBE4EBDE748B5094\DerelictUtil.lib -w -version=Have_derelict_util -I..\..\..\..\..\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\source ..\..\..\..\..\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\source\derelict\util\exception.d ..\..\..\..\..\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\source\derelict\util\loader.d ..\..\..\..\..\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\source\derelict\util\sharedlib.d ..\..\..\..\..\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\source\derelict\util\system.d ..\..\..\..\..\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\source\derelict\util\wintypes.d ..\..\..\..\..\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\source\derelict\util\xtypes.d -vcolumns Copying target from C:\Users\kheaser\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\.dub\build\library-$DFLAGS-windows-x86_64-dmd_2075-288F079949563AF9CBE4EBDE748B5094\DerelictUtil.lib to C:\Users\kheaser\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\lib derelict-al 1.0.3: building configuration "library"... dmd -m64 -I..\ -I..\common -I..\common_game -lib -of..\..\..\..\..\AppData\Roaming\dub\packages\derelict-al-1.0.3\derelict-al\.dub\build\library-$DFLAGS-windows-x86_64-dmd_2075-21F315EBD8043B901FD8CBBDEC82056F\DerelictAL.lib -w -version=Have_derelict_al -version=Have_derelict_util -I..\..\..\..\..\AppData\Roaming\dub\packages\derelict-al-1.0.3\derelict-al\source -I..\..\..\..\..\AppData\Roaming\dub\packages\derelict-util-2.0.6\derelict-util\source ..\..\..\..\..\AppData\Roaming\dub\packages\derelict-al-1.0.3\derelict-al\source\derelict\openal\al.d -vcolumns Co
Re: Real beginner traits question
On Monday, 25 September 2017 at 06:07:58 UTC, H. S. Teoh wrote: On Mon, Sep 25, 2017 at 05:28:13AM +, WhatMeForget via Digitalmars-d-learn wrote: [...] You're not the only one. I stared at this same piece of documentation for a long time before I figured out what it meant. This is another example of poor documentation writing. Please file a bug, and I'll see if I can get around to making an example for it. T Thanks. I just created my first enhancement request, issue 17856.
Mixed up over mixins.
It's stuff like this which makes me very frustrated. Or depressed because it demonstrates just how poor a programmer I am: string printStatement(string message) { return `writeln("` ~ message ~ `");`; } void main() { // Mixins are for mixing in generated code into the source code. // The mixed in code may be generated as a template instance // or a string. mixin(printStatement("hello world")); mixin(`writeln(` ~ `Hello` ~ `);` ); mixin("writeln(`World`);"); } Compiling gives me the errors: Error: undefined identifier Hello To me, `writeln(` ~ `Hello` ~ `);` is a valid D string? Okay, maybe a string expression but a string nevertheless. So, am I giving mixin more magical powers than it possesses? Should we say that mixin needs to be given a "fully pre-formed D compilable" string? Thanks. especially to let me vent.
Re: real simple delegate question.
On Friday, 18 August 2017 at 20:39:38 UTC, angel wrote: On Friday, 18 August 2017 at 02:38:15 UTC, WhatMeForget wrote: [...] This actually appears correct ... The 1-st example: Each call to makeCalculator() increments a static (i.e. shared among all makeCalculator() instances) variable - context. In addition, makeCalculator() generates a random variable. Whereas the delegate merely captures these variables, and the displayed results reflect this. The 2-nd example: There is a single call to makeCalculator(). After this call, context == 1, randy == _apparently 2_. Now the delegate, as has already been said, merely captures these values, so consecutive calls do not change the result. Thanks. So, auto calculator = makeCalculator(); is the actual call of the delegate? "Delegate is function pointer with context" But what is ...calculator(0)); Or maybe another approach would be to ask, what type is the compiler replacing auto with.
Re: I feel the dynamic array .sizeof property is kind of a bait and switch
On Wednesday, 26 July 2017 at 02:32:07 UTC, Adam D. Ruppe wrote: I've hand rolled a function which is working for me currently, but with my coding ability, I'd feel much safer with something official :) You could also do (cast(ubyte[]) array).length. This was my (way over complicated) attempt at the same thing. I'll blame my verbosity because I was trying to teach myself about templates and constraints at the time :) /+ There is a special type of array which acts as a wildcard that can hold arrays of any kind, declared as void[]. The .length of a void array is the length of the data in bytes rather than the number of elements in its original type. " +/ int arrayByteSize(T)(T someArray) if (isDynamicArray!(T)) { ubyte[] arr = cast(ubyte[]) someArray; return cast(int) arr.length; } It just seems like something this basic regarding dynamic arrays should just be built-in. What are you using it for? glBufferData(GL_ARRAY_BUFFER, vertices.arrayByteSize, vertices.ptr, GL_STATIC_DRAW); I find that openGL uses array buffers all over the place. I just keep going back to the idea that such low level functionality should be inherent in either the language or Phobos. If that is even possible.
Re: I feel the dynamic array .sizeof property is kind of a bait and switch
On Wednesday, 26 July 2017 at 02:31:33 UTC, Mike Parker wrote: On Wednesday, 26 July 2017 at 02:24:06 UTC, WhatMeForget wrote: [...] Because .sizeof has nothing to do with how many elements are in the array. It tells you how much space the array itself takes up. Totally agree. .length returns the the number of array elements. With static arrays, the memory for the elements if part of the array itself, so it is counted in the size. For dynamic arrays, it is not. For .sizeof to report the size of the allocated memory would be incorrect. OK, Then I assume the critical thing is that dynamic arrays memory is not part of the array itself. But is this a deal breaker?
unresolved external symbol error (How to resolve?)
Linking... 01_06_coord_systems.obj : error LNK2001: unresolved external symbol _D11common_game12__ModuleInfoZ 01_06_coord_systems.obj : error LNK2001: unresolved external symbol _D14post_processor12__ModuleInfoZ I've gotten plenty of undefined external symbol errors in my time but how does one approach a "unresolved" error. Does this mean I have more than 1 occurrence of the symbol and the linker is confused? And what do the _ModuleInfoZs mean? I've got a package called common_game which has a module named post_processor.d Any suggestions? Thanks.
Re: First time user of LDC and getting newbie problems.
On Tuesday, 13 June 2017 at 12:39:53 UTC, Joseph Rushton Wakeling wrote: On Tuesday, 13 June 2017 at 12:38:03 UTC, Joseph Rushton Wakeling wrote: On Sunday, 11 June 2017 at 21:58:27 UTC, WhatMeForget wrote: Just trying to compile a "Hello World" using dub and ldc2. I presume from your command line you're running Windows? ... I don't know where I got that idea from. Must be having a distracted day. What OS/distro are you running, in any case? Sorry I didn't reply sooner. I just reinstalled everything and it's all good. Something was really screwed up.
Dub or Dmd trying to use some funny path to find linker.exe
Dub or Dmd dies when it can't find the linker. Like so: C:\Users\kheaser\Git\Delivery\projects\00_01_print_ogl_ver>dub run --arch=x86_64 --force Performing "debug" build using dmd for x86_64. derelict-util 2.0.6: building configuration "library"... derelict-al 1.0.3: building configuration "library"... derelict-assimp3 1.3.0: building configuration "library"... derelict-fi 2.0.3: building configuration "library"... derelict-fmod 2.0.4: building configuration "library"... derelict-ft 1.1.3: building configuration "library"... derelict-gl3 1.0.23: building configuration "library"... derelict-glfw3 3.1.3: building configuration "derelict-glfw3-dynamic"... 00_01_print_ogl_ver ~master: building configuration "application"... Linking... Error: can't run 'C:\Users\Administrator\Desktop\VC\\bin\x86_amd64\link.exe', check PATH dmd failed with exit code -1. C:\Users\kheaser\OneDrive for Business\GitHub\Delivery\projects\00_01_print_ogl_ver>where link.exe C:\D\dmd2\windows\bin\link.exe First off, I have no idea why dub (or dmd) is trying to use the path C:\Users\Administrator\Desktop\VC\\bin\x86_amd64\ to find link.exe? I did the where command link.exe to show that the linker is in my PATH at C:\D\dmd2\windows\bin\. So can I specify the linker path explicitly and if so, how is that done? Sorry if this is a stupid question, but I've looked at the documentation all morning and not finding anything. Thanks.
when I run dub within git bash, dub prompts are not displayed. For instance...
kheaser@IT-ASST-SB MINGW64 /c/Users/kheaser/Git/Delivery/projects (master) $ dub init 00_01_print_ogl_ver ... All this white space here is me just pressing the Enter key ... to get the default values. Package recipe format (sdl/json) [json]: Name [00_01_print_ogl_ver]: Description [A minimal D application.]: Author name [kheaser]: License [proprietary]: Copyright string [Copyright © 2017, kheaser]: Add dependency (leave empty to skip) []: Successfully created an empty project in 'C:\Users\kheaser\OneDrive for Business\GitHub\Delivery\projects\00_01_print_ogl_ver'. Package successfully created in 00_01_print_ogl_ver Any recommendations? I guess I could just run two command lines in parallel. One regular Windows command line for dub and another git bash window for GIT commands? Or should Git and Dub be kept firmly apart?
Re: Structure of platform specific vs non platform specific code
On Monday, 8 May 2017 at 21:16:53 UTC, Igor wrote: Hi, I am following Casey Muratori's Handmade Hero and writing it in DLang. This sounds very interesting. Maybe make it a public github project?
Re: Cleaning up Dub/Dmd builds
On Tuesday, 18 April 2017 at 15:15:47 UTC, Stanislav Blinov wrote: On Tuesday, 18 April 2017 at 15:07:27 UTC, WhatMeWorry wrote: When I try to upload these files to my new repo, GitHub (rightfully so) complains that I have too many files. Since I'm using sdl and not json, can I safely delete all the files that pertain to json? Can I do this some way at the command line? You shouldn't upload files from the .dub directory, that's local build cache that shouldn't be published. You can simply add the .dub directory to your .gitignore file. Thanks. That seems like an elegant solution. Sorry if that is documented somewhere. I never came across it or didn't understand it when I did.
Cleaning up Dub/Dmd builds
Just some basic questions regarding Dub projects with GitHub. I'm just getting my toes wet with GitHub so these might be pretty naive questions. I've got about 35 mini dub projects where each project holds an OpenGL tutorial. like so: 01_01_hello_window .dub build application-$DFLAGS-windows-x86_64-dmd_2071-090A2D44A9209535339D8167E6A96BA6" o o o application-$DFLAGS-windows-x86_64-dmd_2071-D8ED32593AF993350341F03512FE4A7C" dub.json source (all my .d files) 01_01_hello_window.exe dub.sdl dub.selections.json 01_02_textures .dub build (etc.) When I try to upload these files to my new repo, GitHub (rightfully so) complains that I have too many files. Since I'm using sdl and not json, can I safely delete all the files that pertain to json? Can I do this some way at the command line? Also, I have tons of empty folders with cryptic names like "application-$DFLAGS-windows-x86_64-dmd_2071-D8ED32593AF993350341F03512FE4A7C" above. Is there some way to suppress these from even being created? Finally, is it problematic to have so many little dub folders? Should I have organized things in a different (better) manner? Thanks.
simple static if / traits question...
I'm doing conditional compilation using static ifs like so: enum bool audio = true; // if audio flag is present and set to true, add to code build static if ( (__traits(compiles, audio)) && audio) playSound(soundSys, BLEEP ); This works, but I thought there might be a simpler way. For instance, after perusing std.traits, I thought I would find something like isPresent(audio) or isSymbol(audio) templates. Or am I being obtuse here? Thanks.
Re: DerelictFmodStudio not found...
On Saturday, 11 February 2017 at 03:10:35 UTC, WhatMeWorry wrote: I followed the instructions for derelict.fmod. // Load the Fmod library. DerelictFmod.load(); // compiles fine. // Load the Fmod studio library. DerelictFmodStudio.load(); but the Studio load ..\common\derelict_libraries.d(122,5): Error: undefined identifier 'DerelictFmodStudio' In the detailed example, I see the code only loads DerelictFmod. Is the documentation out of date? Or am I missing something. Thanks. Does anybody know the exact version of fmod.dll that is needed by DerelictFmod? I don't think I can gleam this from the DUB entry. I've downloaded from FMOD's website their Windows api 1.09, 1.08, etc. and keep getting the following runtime abort: fmod.dll - %1 is not a valid Win32 application.
DerelictFmodStudio not found...
I followed the instructions for derelict.fmod. // Load the Fmod library. DerelictFmod.load(); // compiles fine. // Load the Fmod studio library. DerelictFmodStudio.load(); but the Studio load ..\common\derelict_libraries.d(122,5): Error: undefined identifier 'DerelictFmodStudio' In the detailed example, I see the code only loads DerelictFmod. Is the documentation out of date? Or am I missing something. Thanks.
Re: Is there anything fundamentally wrong with this code?
On Friday, 3 February 2017 at 18:37:15 UTC, Johan Engelen wrote: On Friday, 3 February 2017 at 17:20:43 UTC, WhatMeWorry wrote: [...] The error is in this line. Instead of assigning to the `postProc` at module scope, you are defining a new local variable and assigning to it. [...] Thank you so much. This is where I deserve a big Duh. I guess there is no way to to make this idiot proof. I'll print it out and hang it over my desk.
Is there anything fundamentally wrong with this code?
The code below compiles fine but I always get a run time abort with the error down below. Isn't the postProc at module scope so shouldn't the class instance always be around (ie not deallocated?) If it helps, this was translated from C++ code. Thanks. -file post_processor.d -- module post_processor; class PostProcessor { ... GLuint FBO; } -file game.d --- module game; PostProcessor postProc; // just a declaration (no memory allocation) class Game { ... void initGame(){ ... PostProcessor postProc = new PostProcessor(...); ... } ... void update(GLfloat deltaTime){ ... writeln("Right Before"); writeln("postProcesor.FBO = ", postProc.FBO); writeln("Right After); ... } ... } Right Before Program exited with code -1073741819 myapp exited with code 2
A matter of propiety
module_common import app; // Ugly? Bad? Better way? common_func() { static if (compileTimeFlag1) codeBlockA static if (compileTimeFlag2) codeBlockB static if (compileTimeFlag3) codeBlockC } I want to have many stand-alone programs that calls the common function. Each app.d is its own separate directory so I can use the same name. app.d static bool compileTimeFlag1 = true; common_func() app.d static bool compileTimeFlag1 = true; static bool compileTimeFlag2 = true; common_func() app.d static bool compileTimeFlag1 = true; static bool compileTimeFlag2 = true; static bool compileTimeFlag3 = true; common_func() I've got this working, but only if I add an "import app;" to module_common. Otherwise I get, "Error: undefined identifier compileTimeFlags I want to keep all the compileTimeFlags in the main modules. Seems like the most logical place to put them. But it seems like I'm committing some great sin by doing this. Maybe it's my C++ days, but it just seems wrong to have a module import the main module? Is there a more elegant approach? Just another quick question: is the module that holds the main() function just the same as any other module? Or is there some secret sauce? (Besides the point of entry) Thanks.