Importing D libraries
I must be missing something incredibly obvious here, but I can't find out what it is... I'm trying to build a very simple test program for LuaD, right now it simply imports the library. But it throws a linker error for some reason. Here's the program I'm trying to compile: import std.stdio; import luad.all; int main() { readln(); return 0; } This is what I use to compile it: dmd -ILuaD LuaTest.d This is the error it gives me: LuaTest.o:(.data+0x18): undefined reference to `_D4luad3all12__ModuleInfoZ' collect2: ld returned 1 exit status --- errorlevel 1 I got LuaD by simply performing a git clone from here: https://github.com/JakobOvrum/LuaD Using Linux, DMD64 v2.053.
Re: Importing D libraries
On Tue, Jul 26, 2011 at 2:02 AM, Dainius (GreatEmerald) past...@gmail.comwrote: I must be missing something incredibly obvious here, but I can't find out what it is... I'm trying to build a very simple test program for LuaD, right now it simply imports the library. But it throws a linker error for some reason. Here's the program I'm trying to compile: import std.stdio; import luad.all; int main() { readln(); return 0; } This is what I use to compile it: dmd -ILuaD LuaTest.d This is the error it gives me: LuaTest.o:(.data+0x18): undefined reference to `_D4luad3all12__ModuleInfoZ' collect2: ld returned 1 exit status --- errorlevel 1 I got LuaD by simply performing a git clone from here: https://github.com/JakobOvrum/LuaD Using Linux, DMD64 v2.053. DMD will parse files you import, but won't generate output for them unless you specify them on the command line. If you want it to generate code for luad.all (which is what the linker says is missing), you need to compile like this: dmd -ILuaD LuaTest.d LuaD/luad/all.d There are probably other files you need in LuaD, so you might try generating a lib: dmd -ILuaD -lib -ofLuaD.lib LuaD/luad/*.d [insert other paths as appropriate] Which you can then use like this: dmd -ILuaD LuaTest.d LuaD.lib
Re: Importing D libraries
Hmm, apparently it requires a strict compilation order. If I just add all .d files in no particular order, I get lots of linker errors, for example: LuaTest.o: In function `_D4luad4base9LuaObject9checkTypeFPT4luad1c3lua9lua_StateiiPxaZv': LuaD/luad/c/lua.d:(.text._D4luad4base9LuaObject9checkTypeFPT4luad1c3lua9lua_StateiiPxaZv+0x1a): undefined reference to `lua_type' LuaD/luad/c/lua.d:(.text._D4luad4base9LuaObject9checkTypeFPT4luad1c3lua9lua_StateiiPxaZv+0x2b): undefined reference to `lua_typename' LuaD/luad/c/lua.d:(.text._D4luad4base9LuaObject9checkTypeFPT4luad1c3lua9lua_StateiiPxaZv+0x47): undefined reference to `luaL_error' LuaTest.o: In function `_D4luad4base9LuaObject4typeMFNdZE4luad4base7LuaType': LuaD/luad/c/lua.d:(.text._D4luad4base9LuaObject4typeMFNdZE4luad4base7LuaType+0x45): undefined reference to `lua_type' LuaTest.o: In function `_D4luad4base9LuaObject8opEqualsMFC6ObjectZb': LuaD/luad/c/lua.d:(.text._D4luad4base9LuaObject8opEqualsMFC6ObjectZb+0xa1): undefined reference to `lua_equal' LuaTest.o: In function `_D4luad5table8LuaTable12setMetaTableMFC4luad5table8LuaTableZv': LuaD/luad/c/lua.d:(.text._D4luad5table8LuaTable12setMetaTableMFC4luad5table8LuaTableZv+0x5e): undefined reference to `lua_setmetatable' LuaTest.o: In function `_D4luad5table8LuaTable12getMetaTableMFZC4luad5table8LuaTable': LuaD/luad/c/lua.d:(.text._D4luad5table8LuaTable12getMetaTableMFZC4luad5table8LuaTable+0x45): undefined reference to `lua_getmetatable' How do I work around that? I know that things like lua_type are in luad/c/lua.d. How do I tell that to the compiler? How do I determine the correct order of files?
Re: Importing D libraries
Andrew Wiley wiley.andre...@gmail.com wrote in message news:mailman.1914.1311673246.14074.digitalmars-d-le...@puremagic.com... On Tue, Jul 26, 2011 at 2:02 AM, Dainius (GreatEmerald) past...@gmail.comwrote: I must be missing something incredibly obvious here, but I can't find out what it is... I'm trying to build a very simple test program for LuaD, right now it simply imports the library. But it throws a linker error for some reason. Here's the program I'm trying to compile: import std.stdio; import luad.all; int main() { readln(); return 0; } This is what I use to compile it: dmd -ILuaD LuaTest.d This is the error it gives me: LuaTest.o:(.data+0x18): undefined reference to `_D4luad3all12__ModuleInfoZ' collect2: ld returned 1 exit status --- errorlevel 1 I got LuaD by simply performing a git clone from here: https://github.com/JakobOvrum/LuaD Using Linux, DMD64 v2.053. DMD will parse files you import, but won't generate output for them unless you specify them on the command line. If you want it to generate code for luad.all (which is what the linker says is missing), you need to compile like this: dmd -ILuaD LuaTest.d LuaD/luad/all.d There are probably other files you need in LuaD, so you might try generating a lib: dmd -ILuaD -lib -ofLuaD.lib LuaD/luad/*.d [insert other paths as appropriate] Which you can then use like this: dmd -ILuaD LuaTest.d LuaD.lib Starting with DMD 2.054, you can also just do this: rdmd -ILuaD --build-only -ofmyapp LuaTest.d You can do it on older DMDs, too, you'll just need a newer RDMD: https://github.com/D-Programming-Language/tools/blob/6463c0ef6eab352dd0767b6bd174aca46e1abc95/rdmd.d
operator overloading compilation error
Hi I'm trying to overload the + and - operators for a struct but I get this error test.d(47): Error: incompatible types for ((v1) - (v2)): 'Vecf!(1u)' and 'Vecf!(1u)' (the line corresponds to the last assert) doing something like this struct Vecf(uint n) { ... Vecf!n opBinary(string op)(Vecf!n other) if (op == + || op == -) {...} } void main() { Vecf!1u v1 = Vecf!1u(3f); Vecf!1u v2 = Vecf!1u(5f); Vecf!1u r = Vecf!1u(-2f); assert ((v1.opBinary!-(v2)) == r); assert ((v1 - v2) == r); } removing the last assert or replacing (Vecf!n other) by (Vecf!1u other) in the function declaration works fine, but it's not what I want Any ideas? maybe I'm overloading the operators in the wrong way (it worked in a very similar test though)? Thanks!! Here's the full code: --- module test; import std.stdio; struct Vecf(uint n) { float[n] data; this(float[n] args ...) { foreach (i, a; args) { data[i] = a; } } float opIndex(uint i) { return data[i]; } float opIndexAssign(float value, uint i) { data[i] = value; return value; } Vecf!n opBinary(string op)(Vecf!n other) if (op == + || op == -) { Vecf!n ret; for (size_t i = 0; i n; i++) { mixin(ret[i] = this[i] ~ op ~ other[i];); } return ret; } } void main() { Vecf!1u v1 = Vecf!1u(3f); Vecf!1u v2 = Vecf!1u(5f); Vecf!1u r = Vecf!1u(-2f); assert ((v1.opBinary!-(v2)) == r); assert ((v1 - v2) == r); } --
Re: Importing D libraries
I updated the DMD and tried RDMD, but still no luck. Linker errors galore. You can see all of them here: http://pastebin.com/C6cRVGKt
Re: Importing D libraries
On Tue, 26 Jul 2011 13:06:56 +0200, Dainius (GreatEmerald) past...@gmail.com wrote: I updated the DMD and tried RDMD, but still no luck. Linker errors galore. You can see all of them here: http://pastebin.com/C6cRVGKt You need to link the library as well, try adding -L-llua (I think) to the command.
Re: Importing D libraries
Ah, that did the trick, thanks!
Re: Importing D libraries
I compiled a test for LuaD a few days ago without problems. I think you need to link to the lua library On Tue, Jul 26, 2011 at 8:06 AM, Dainius (GreatEmerald) past...@gmail.comwrote: I updated the DMD and tried RDMD, but still no luck. Linker errors galore. You can see all of them here: http://pastebin.com/C6cRVGKt
Re: How do I call super or object.opAssign for classes?
Hi, isn't that the way it's supposed to work? I mean void show(int a) { writeln(a); } void main() { show(null); } won't compile either. Shouldn't bar be some kind of pointer? btw, today I read opAssign can no longer be overloaded for class objects here: http://www.d-programming-language.org/features2.html is that no longer valid?
Re: operator overloading compilation error
Diego Canuhé: I'm trying to overload the + and - operators for a struct but I get this error test.d(47): Error: incompatible types for ((v1) - (v2)): 'Vecf!(1u)' and 'Vecf!(1u)' (the line corresponds to the last assert) It's a dmd bug, and I think it's already in Bugzilla. This is workaround code: struct Vecf(uint n) { float x; Vecf opBinary(string op)(Vecf other) if (op == + || op == -) { mixin(return Vecf(this.x ~ op ~ other.x);); } } void main() { alias Vecf!1 V; auto v1 = V(3f); auto v2 = V(5f); auto r = V(-2f); assert ((v1.opBinary!-(v2)) == r); // better to use an approximate == assert ((v1 - v2) == r); // better to use an approximate == } Bye, bearophile
Re: operator overloading compilation error
thanks! On Tue, Jul 26, 2011 at 9:12 AM, bearophile bearophileh...@lycos.comwrote: Diego Canuhé: I'm trying to overload the + and - operators for a struct but I get this error test.d(47): Error: incompatible types for ((v1) - (v2)): 'Vecf!(1u)' and 'Vecf!(1u)' (the line corresponds to the last assert) It's a dmd bug, and I think it's already in Bugzilla. This is workaround code: struct Vecf(uint n) { float x; Vecf opBinary(string op)(Vecf other) if (op == + || op == -) { mixin(return Vecf(this.x ~ op ~ other.x);); } } void main() { alias Vecf!1 V; auto v1 = V(3f); auto v2 = V(5f); auto r = V(-2f); assert ((v1.opBinary!-(v2)) == r); // better to use an approximate == assert ((v1 - v2) == r); // better to use an approximate == } Bye, bearophile
Re: How do I call super or object.opAssign for classes?
On Tue, 26 Jul 2011 07:54:54 -0400, Diego Canuhé canuh...@gmail.com wrote: Hi, isn't that the way it's supposed to work? I mean void show(int a) { writeln(a); } void main() { show(null); } won't compile either. Shouldn't bar be some kind of pointer? null should be considered as the type of the class, not void *. You should not be able to override the behavior of opAssign as it pertains to assigning to a class instance. In other words, you should *never* be able to override x = null where x is a class instance. btw, today I read opAssign can no longer be overloaded for class objects here: http://www.d-programming-language.org/features2.html is that no longer valid? Here is the spec. I would not trust that features2, it's probably out of date. http://www.d-programming-language.org/operatoroverloading.html#Assignment -Steve
Re: Very strange linker error
Am 23.07.2011 17:10, schrieb Mafi: I'm trying to rebuild my projects with new dmd and after fixing some minor issues in my code I get the following: Warning: As of Phobos 2.054, std.file.listDir has been scheduled for deprecation in August 2011. Please use std.file.dirEntries instead. OPTLINK (R) for Win32 Release 8.00.12 Copyright (C) Digital Mars 1989-2010 All rights reserved. http://www.digitalmars.com/ctg/optlink.html obj\main.obj(main) Offset 35B56H Record Type 00C3 Error 1: Previous Definition Different : _D5mysdl5input8Joystick6__ctorM --- errorlevel 1 So I went to http://www.digitalmars.com/d/2.0/abi.html (which I by the wy couldn't find on d-p-l.org) and it seems to be an incorrect mangling because there's no 'type' after M but maybe it's a special case for the constructor. So looked for mysdl.input.Joystick.this(...). The struct (!) Joystick in input.d has two constructors: public this(SDL_Joystick* somePtr) { this.joyptr = somePtr; } public this(int index) in { assert(index = 0); assert(index Joystick.getCount()); } body { this(SDL_JoystickOpen(index)); } No overlaping. So I went dumping all my object files and I found that dmd generated this strange sambol in input.obj twice. So it's not optlink's fault but dmd's! I'd really like to solve this problem because otherwise this would be second release in a row that I can't use. The worst thing is I don't even now any ugly workaround. :( Mafi I commented out the first contructor and inlined it into the other: no linker errors. But it used to compile with two constructors. If it's ok that it does not compile, the compiler should catch it and not the linker IMO. Is it a bug in the compiler?? Mafi
Error building dfl on dmd 2.054
I've just added default: assert(0) on the switches, but I got an error I don't know how to solve: tabcontrol.d(18): Error: class dfl.tabcontrol.TabPage use of dfl.control.Control.opEquals(Control ctrl) hidden by TabPage is deprecated Any ideas? The best would of course be if the maintainer fixes the issues, but I don't know how long this will be.
Re: Error building dfl on dmd 2.054
simendsjo: I've just added default: assert(0) on the switches, but I got an error I don't know how to solve: See: http://d.puremagic.com/issues/show_bug.cgi?id=6373 Bye, bearophile
Re: error when std.range.Cycle of static array is a member
On Mon, 25 Jul 2011 11:25:17 -0400, Steven Schveighoffer schvei...@yahoo.com wrote: Please file a 'rejects-valid' bug. http://d.puremagic.com/issues/show_bug.cgi?id=6385
Re: Error building dfl on dmd 2.054
simendsjo Wrote: I've just added default: assert(0) on the switches, but I got an error I don't know how to solve: tabcontrol.d(18): Error: class dfl.tabcontrol.TabPage use of dfl.control.Control.opEquals(Control ctrl) hidden by TabPage is deprecated Any ideas? The best would of course be if the maintainer fixes the issues, but I don't know how long this will be. I just made a pull request to fix this in the unofficial repo. But Bearophile's alias is probably the correct solution.
Re: Error building dfl on dmd 2.054
Jesse Phillips Wrote: I just made a pull request to fix this in the unofficial repo. But Bearophile's alias is probably the correct solution. Forgot to give you the quick link: https://github.com/Rayerd/dfl/pull/3
Re: Importing D libraries
Pelle pelle.mans...@gmail.com wrote in message news:op.vy74cwejzu79i9@pelle-d2608-a1... On Tue, 26 Jul 2011 13:06:56 +0200, Dainius (GreatEmerald) past...@gmail.com wrote: I updated the DMD and tried RDMD, but still no luck. Linker errors galore. You can see all of them here: http://pastebin.com/C6cRVGKt You need to link the library as well, try adding -L-llua (I think) to the command. A better way to do it is just include this in your code: pragma(lib, lua); // Assuming the lib file is named lua.lib Benefits: - One less cmd-line param. - Should work the same on both windows and posix (the linker args are completely different between windows and posix).
Re: Importing D libraries
On 7/26/11, Nick Sabalausky a@a.a wrote: Pelle pelle.mans...@gmail.com wrote in message news:op.vy74cwejzu79i9@pelle-d2608-a1... On Tue, 26 Jul 2011 13:06:56 +0200, Dainius (GreatEmerald) past...@gmail.com wrote: I updated the DMD and tried RDMD, but still no luck. Linker errors galore. You can see all of them here: http://pastebin.com/C6cRVGKt You need to link the library as well, try adding -L-llua (I think) to the command. A better way to do it is just include this in your code: pragma(lib, lua); // Assuming the lib file is named lua.lib Benefits: - One less cmd-line param. - Should work the same on both windows and posix (the linker args are completely different between windows and posix). Drawbacks: - Not implemented in GDC yet.
Re: Error building dfl on dmd 2.054
On 26.07.2011 20:49, Jesse Phillips wrote: Jesse Phillips Wrote: I just made a pull request to fix this in the unofficial repo. But Bearophile's alias is probably the correct solution. Forgot to give you the quick link: https://github.com/Rayerd/dfl/pull/3 !? Now I'm a bit lost. It says that repo is unofficial. The SVN repo seems alive as it was last updated a couple of months ago.
Re: Error building dfl on dmd 2.054
On Tue, 26 Jul 2011 22:22:39 +0200, simendsjo wrote: On 26.07.2011 20:49, Jesse Phillips wrote: Jesse Phillips Wrote: I just made a pull request to fix this in the unofficial repo. But Bearophile's alias is probably the correct solution. Forgot to give you the quick link: https://github.com/Rayerd/dfl/pull/3 !? Now I'm a bit lost. It says that repo is unofficial. The SVN repo seems alive as it was last updated a couple of months ago. The author is maintaining it. But there was a good time while it didn't compile with the latest and so a published fix was made. As to whether there was an attempted patch submission, I don't know. But I'm going with github because it is damn easy to contribute, and publicize work sooner than a review process allows. It would be interesting if Christopher forked his project and continued working from github (its not like he doesn't get the credit).