Thread overview | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 26, 2011 Re: Importing D libraries | ||||
---|---|---|---|---|
| ||||
Attachments:
| On Tue, Jul 26, 2011 at 2:02 AM, Dainius (GreatEmerald)
<pastas4@gmail.com>wrote:
> 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
|
July 26, 2011 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? |
July 26, 2011 Re: Importing D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Wiley | "Andrew Wiley" <wiley.andrew.j@gmail.com> wrote in message news:mailman.1914.1311673246.14074.digitalmars-d-learn@puremagic.com... > On Tue, Jul 26, 2011 at 2:02 AM, Dainius (GreatEmerald) > <pastas4@gmail.com>wrote: > >> 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 |
July 26, 2011 Re: Importing D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | 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 |
July 26, 2011 Re: Importing D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dainius (GreatEmerald) | On Tue, 26 Jul 2011 13:06:56 +0200, Dainius (GreatEmerald) <pastas4@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.
|
July 26, 2011 Re: Importing D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pelle | Ah, that did the trick, thanks! |
July 26, 2011 Re: Importing D libraries | ||||
---|---|---|---|---|
| ||||
Attachments:
| 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)
<pastas4@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
>
|
July 26, 2011 Re: Importing D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pelle | "Pelle" <pelle.mansson@gmail.com> wrote in message news:op.vy74cwejzu79i9@pelle-d2608-a1... > On Tue, 26 Jul 2011 13:06:56 +0200, Dainius (GreatEmerald) <pastas4@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). |
July 26, 2011 Re: Importing D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On 7/26/11, Nick Sabalausky <a@a.a> wrote:
> "Pelle" <pelle.mansson@gmail.com> wrote in message news:op.vy74cwejzu79i9@pelle-d2608-a1...
>> On Tue, 26 Jul 2011 13:06:56 +0200, Dainius (GreatEmerald)
>> <pastas4@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.
|
July 27, 2011 Re: Importing D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On 2011-07-26 21:34, Andrej Mitrovic wrote: > On 7/26/11, Nick Sabalausky<a@a.a> wrote: >> "Pelle"<pelle.mansson@gmail.com> wrote in message >> news:op.vy74cwejzu79i9@pelle-d2608-a1... >>> On Tue, 26 Jul 2011 13:06:56 +0200, Dainius (GreatEmerald) >>> <pastas4@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. Still not implemented in GDC?? -- /Jacob Carlborg |
Copyright © 1999-2021 by the D Language Foundation