How to create a native library

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

How to create a native library

Post by leiradel »

Hi All,

I'm trying to create a native library to use with LÖVE, but I don't know how to create the DLL.

Obviously, my DLL calls Lua functions, so I must link the object file against something that provides these functions. However:

1. There isn't a Lua DLL in the 0.8.0 LÖVE distribution to link against.
2. I can't link against a static Lua library because LÖVE would use one version of the code and my DLL, another.
3. I don't think I should LoadLibrary love.exe and get function pointers for Lua functions in there, and I don't think they are dllexported anyway.

I think option #1 would be the right way to tackle this, but LÖVE links against Lua statically. How should I link my DLL?

Thanks in advance,

Andre
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: How to create a native library

Post by Boolsheet »

Yeah, it's a bit ugly with 0.8.0. It will be better in 0.9.0.
2. I can't link against a static Lua library because LÖVE would use one version of the code and my DLL, another.
That should work more or less, Lua's API is lenient like that. It's obviously not the right thing to do, but I haven't encountered a library that didn't work (although I didn't test many).

Good thing 0.9.0 is coming soon™. Maybe we can tickle an import library or export file out of rude. :P
Shallow indentations.
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: How to create a native library

Post by leiradel »

Well, that will do before 0.9.0.

What Lua version is the precompiled LÖVE 0.8.0 linked against to?

Thanks,

Andre
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: How to create a native library

Post by Boolsheet »

The official LÖVE 0.8.0 binary for Windows x86 has Lua 5.1.4. At least that's what the version string in the executable says.
Shallow indentations.
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: How to create a native library

Post by leiradel »

Thanks!
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: How to create a native library

Post by leiradel »

Well, I don't think it works...

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
0x6c94ad56 in newkey () from c:\Users\aleirade\Dropbox\MinGW_home\luadm\love-0.8.0-win-x86\luadatamatrix.dll
(gdb) bt
#0  0x6c94ad56 in newkey () from c:\Users\aleirade\Dropbox\MinGW_home\luadm\love-0.8.0-win-x86\luadatamatrix.dll
#1  0x6c94ab5b in luaH_setnum () from c:\Users\aleirade\Dropbox\MinGW_home\luadm\love-0.8.0-win-x86\luadatamatrix.dll
#2  0x6c943ba4 in lua_rawseti () from c:\Users\aleirade\Dropbox\MinGW_home\luadm\love-0.8.0-win-x86\luadatamatrix.dll
#3  0x6c9414c9 in get_codes (L=0x343548) at luadatamatrix.cpp:85
#4  0x01494282 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
LÖVE is compiled with MS' compiler, I'm compiling Lua with MinGW, so there must be some incompatibility between the generated code (alignment?) that is randomly causing this problem.

I'll try to compile LÖVE myself, and link it against lua51.dll.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: How to create a native library

Post by Boolsheet »

leiradel wrote:LÖVE is compiled with MS' compiler, I'm compiling Lua with MinGW, so there must be some incompatibility between the generated code (alignment?) that is randomly causing this problem.
Oh, yeah. If you do stuff like that.. :P

You could link against a lua51.dll built with msvc. https://bitbucket.org/Boolsheet/love_wi ... -5.1.5.zip

Rebuilding LÖVE would be the clean thing to do indeed.
Shallow indentations.
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: How to create a native library

Post by leiradel »

:halloween:

Code: Select all

1>LINK : fatal error C1047: The object or library file 'lib\libmpg123.lib' was created with an older compiler than other objects; rebuild old objects and libraries
1>LINK : fatal error LNK1257: code generation failed
Does anyone know if it's possible to get an older MS compiler without Visual Studio? I can handle the compilation via command line.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: How to create a native library

Post by Boolsheet »

I don't think they ship the compilers and Visual Studio separately. Probably because both rely on some shared library.

Perhaps in the Windows SDK? I remember that Visual Studio 9 Express didn't have x86-64 compilers and needed the Windows SDK for them. That probably has changed with the Windows SDK 7 and 8 though.

I'll try to put some batch files together for the dependencies. Very minimal approach at a build system. :P
Shallow indentations.
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: How to create a native library

Post by leiradel »

No game. I can compile LÖVE with my version of MS compiler but then it complains about the compiler used to compile the objects in the lib files being old.

I tried to compile LÖVE with MinGW, but there's one symbol in one of the objects that is undefined during link: __security_cookie

Oh well, I'll try to locate some SDL bindings for Lua that I wrote a couple of years ago and give it a go. Let's see if LÖVE 0.9.0 will have better support for the compilation of native libraries on Windows.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], slime and 70 guests