External C dll

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
Strombolio
Prole
Posts: 2
Joined: Sun Dec 20, 2015 5:02 am

External C dll

Post by Strombolio »

Hi, I'm experimenting and trying to make a collision manager dll, following these two pages
http://www.mingw.org/wiki/sampleDLL
http://www.troubleshooters.com/codecorn ... alls_c.htm

But when I try to require the library from Love, it gives me this

error loading module 'test' from file '.\test.dll':
%1 is not a valid Win32 application.

I also tried ffi, but it just gave me a nil
I'm baffled and don't know where to go next, please help? :3
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: External C dll

Post by slime »

Be sure to build it for the same architecture as your copy of LÖVE - i.e. make a 32 bit build if you're running 32 bit love, or a 64 bit build if you're running 64 bit love.
User avatar
giantofbabil
Prole
Posts: 32
Joined: Tue Dec 15, 2015 6:07 pm

Re: External C dll

Post by giantofbabil »

I'm pretty new to Love2D and programming in general but what is the advantage of a .dll over another .lua file to manage something?

Code: Select all

if enemy == lowerClassSaiyan and powerLevel > 9000 then
    love.graphics.print("What?! 9000?! There's no way that could be right!", 10, 200)
else
    love.graphics.print("You fool!", 10, 200)
end
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: External C dll

Post by bobbyjones »

C code could potentially be faster or flexible. But there is more disadvantages than advantages. Better off using ffi if you want to use c to boost the performance
Strombolio
Prole
Posts: 2
Joined: Sun Dec 20, 2015 5:02 am

Re: External C dll

Post by Strombolio »

slime wrote:Be sure to build it for the same architecture as your copy of LÖVE - i.e. make a 32 bit build if you're running 32 bit love, or a 64 bit build if you're running 64 bit love.
Aw, I always forget about that! :?

Now ffi gives me
missing declaration for symbol 'test'

and require gives me
error loading module 'test' from file '.\test.dll':
The specified procedure could not be found.

But I think I did it right
int __declspec(dllexport) test(int num){
return num+5;
}

gcc -shared -o test.dll test.c -Wl,--out-implib,test.a

and I also tried
gcc test.c -shared -o test.dll -Wl,--no-undefined,--enable-runtime-pseudo-reloc

and I also tried adding __stdcall to the function, but I don't really know what that does :huh: ^^
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: External C dll

Post by airstruck »

Now ffi gives me
missing declaration for symbol 'test'
I don't see any Lua code here so I'll just go out on a limb and guess that the error's exactly what it looks like and the symbol was never declared (something like ffi.cdef 'int test (int);').

This is covered at the very beginning of the documentation for the ffi api.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Semrush [Bot] and 3 guests