Importing D libraries

Nick Sabalausky a at a.a
Tue Jul 26 03:37:43 PDT 2011


"Andrew Wiley" <wiley.andrew.j at gmail.com> wrote in message 
news:mailman.1914.1311673246.14074.digitalmars-d-learn at puremagic.com...
> On Tue, Jul 26, 2011 at 2:02 AM, Dainius (GreatEmerald)
> <pastas4 at 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





More information about the Digitalmars-d-learn mailing list