Thread overview
Compiling Lua for D
Feb 15, 2012
Mars
Feb 15, 2012
Andrej Mitrovic
Feb 15, 2012
Mars
Feb 15, 2012
Trass3r
Feb 15, 2012
Mars
Feb 15, 2012
Trass3r
Feb 15, 2012
Mars
Feb 16, 2012
Jesse Phillips
Feb 16, 2012
Mars
February 15, 2012
Hello, everybody.

Originally I've posted this in the C++ section, but seeing how the posts there are almost ancient, I'll post it here as well, where probably more people will see it.

I'm trying to compile Lua, using DMC, to use it in D. I got the compilation working, but I have no clue, on how to turn the .obj files into a .lib. In D I'd use the -lib argument, but I couldn't figure out how to do this with DMC/OPTLINK yet. If I just do
> dmc src\lapi.c src\lauxlib.c [...] -olua5.1.lib
I get
> OPTLINK : Warning 134: No Start Address
and when trying to use this .lib
> Not a Valid Library File
from DMD.

What's the correct way to do this?

Mars
February 15, 2012
Have you tried https://github.com/JakobOvrum/LuaD ? It has binaries here: http://github.com/JakobOvrum/LuaD/tree/binaries
February 15, 2012
On Wednesday, 15 February 2012 at 16:35:01 UTC, Andrej Mitrovic wrote:
> Have you tried https://github.com/JakobOvrum/LuaD ? It has binaries
> here: http://github.com/JakobOvrum/LuaD/tree/binaries

LuaD works fine, but I'd rather learn to compile stuff like this myself. It will get me further in the long run^^
February 15, 2012
> LuaD works fine, but I'd rather learn to compile stuff like this myself. It will get me further in the long run^^

Try to switch to gdc.
dmc, optlink & Co. must die a bloody death anyway :)
February 15, 2012
On Wednesday, 15 February 2012 at 15:02:36 UTC, Mars wrote:
> What's the correct way to do this?

I guess I did it. Using lib, I was able to bind those obj files to a lib file.
> lib -c obj_files...

I really have to learn a bit more about this stuff... to successfully compile a program with this lib, I have to make another one, using LuaD's "C" header files, so all symbols are found. I assume I could compile those, and include them in my other lib... but why is that? Shouldn't the Lua lib, and the importing of those files be enough? I couldn't really wrap my head around that yet, if I import something, that's not in my project, aren't those files included? Is that why I also have to make a lib for it? What exactly happens when importing?
February 15, 2012
On Wednesday, 15 February 2012 at 19:44:41 UTC, Trass3r wrote:
>> LuaD works fine, but I'd rather learn to compile stuff like this myself. It will get me further in the long run^^
>
> Try to switch to gdc.
> dmc, optlink & Co. must die a bloody death anyway :)

I guess GDC uses COFF? That would definitely be handy... although I couldn't compile and debug from VS anymore in that case, and that would be unfortunate^^"
February 15, 2012
> I guess GDC uses COFF? That would definitely be handy... although I couldn't compile and debug from VS anymore in that case, and that would be unfortunate^^"

Just recently Rainer added gdc support to cv2pdb.
February 16, 2012
On Wednesday, 15 February 2012 at 19:49:13 UTC, Mars wrote:
> I assume I could compile those, and include them in my other lib... but why is that? Shouldn't the Lua lib, and the importing of those files be enough? I couldn't really wrap my head around that yet, if I import something, that's not in my project, aren't those files included? Is that why I also have to make a lib for it? What exactly happens when importing?

Importing just tells the compiler that you wish to use the symbols for the imported module. This is different from C`s include as that is just a text replacement.

Importing does not make those modules compiled into you obj file. Each module is given there own object file and generally this is how you`ll build each C file. These obj files can then be packaged in a lib.

There is however a difference between the compile and link stage. During compilation the important part is to know what is contained in an obj/lib. This is why we import/include, the signature of the external code tells the compiler the calling convention being used. The linker on the other hand does not care about the imports and is only putting the used code together (linking).

So when building an application against Lua it must provide the header files such that the compiler knows what will be found in the library/external code.

BTW, I totally recommend LuaD when interacting with lua.
February 16, 2012
On Thursday, 16 February 2012 at 05:06:13 UTC, Jesse Phillips wrote:
> BTW, I totally recommend LuaD when interacting with lua.

Thank you for the explanation.
I've started with LuaD, but I kinda didn't like it, can't exactly say why. I rather want to use Lua directly for now, and maybe write my own wrapper later.