Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Unable to load compiled C lib in LUA (64-bit DLL)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Scorm
Newbie cheater
Reputation: 0

Joined: 06 Dec 2018
Posts: 11

PostPosted: Mon Dec 17, 2018 4:17 pm    Post subject: Unable to load compiled C lib in LUA (64-bit DLL) Reply with quote

Hello,

I tried to "require" a compiled C lib in LUA from CE 6.8.1 64-bit.
The lib was compiled with GCC, using the LUA header from CE's install dir. I also used "lua53-64.dll".

The DLL was placed in CE's root dir. On LUA script execution :
Code:
Error:error loading module 'winapi' from file 'C:\Program Files (x86)\Cheat Engine 6.8.1\winapi.dll':
   %1 is not a valid Win32 application.


At the moment, I am unable to compile a 32-bit DLL. It is required to do so ?
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 146

Joined: 25 Jan 2006
Posts: 7571
Location: 127.0.0.1

PostPosted: Mon Dec 17, 2018 6:07 pm    Post subject: Reply with quote

If you are using 64bit CE, you need to use a 64bit DLL.
If you want to load a 32bit DLL, then use 32bit CE.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Scorm
Newbie cheater
Reputation: 0

Joined: 06 Dec 2018
Posts: 11

PostPosted: Mon Dec 17, 2018 7:17 pm    Post subject: Reply with quote

I used CE 64-bit... so I am very confused... like you probably.

EDIT : Downloaded 32-bit compiler to try and compile 32-bit DLL to see if it would work and ended up showing the same error message.

Tried to recompile again in 64-bit, compilation error from GCC :
Code:
...\winapi>REM compiling for mingw against msvcrt

...\winapi>set LUA_DIR=...\winapi

...\winapi>set CFLAGS=-c -g -DPSAPI_VERSION=1  -I"...\winapi"

...\winapi>gcc -c -g -DPSAPI_VERSION=1  -I"...\winapi" winapi.c

...\winapi>gcc -c -g -DPSAPI_VERSION=1  -I"...\winapi" wutils.c

...\winapi>gcc -g -shared winapi.o wutils.o "...\winapi\lua53-64.dll" -lpsapi -lMpr -o winapi.dll

...lua53-64.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status


Last edited by Scorm on Tue Dec 18, 2018 8:14 am; edited 1 time in total
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 146

Joined: 25 Jan 2006
Posts: 7571
Location: 127.0.0.1

PostPosted: Mon Dec 17, 2018 10:33 pm    Post subject: Reply with quote

You are still mixing bit modes which you can't.

If you are using 32bit CE, you have to use 32bit DLLs.
If you are using 64bit CE, you have to use 64bit DLLs.

You need to compile things for the proper bit mode you plan to use.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 360

Joined: 09 May 2003
Posts: 21154
Location: The netherlands

PostPosted: Tue Dec 18, 2018 12:55 am    Post subject: Reply with quote

you need to build with the .lib , not the dll
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
Scorm
Newbie cheater
Reputation: 0

Joined: 06 Dec 2018
Posts: 11

PostPosted: Tue Dec 18, 2018 8:13 am    Post subject: Reply with quote

Dark Byte wrote:
you need to build with the .lib , not the dll


I checked my Win7 "PATH" and the path to the x86 compiler was inserted before the x64 so I removed it...

Tried with lua53-64.lib and here is the compilation output :


Code:

...\winapi>REM compiling for mingw against msvcrt

...\winapi># set LUA_DIR=D:\dev\lua\luajit-2.0\src

...\winapi>set LUA_INCLUDE=C:\Program Files (x86)\Cheat Engine 6.8.1\plugins

...\winapi>set LUA_LIB=C:\Program Files (x86)\Cheat Engine 6.8.1\plugins\lua53-64.lib

...\winapi>set CFLAGS=-c -m64 -O1 -DPSAPI_VERSION=1  -I"C:\Program Files (x86)\Cheat Engine 6.8.1\plugins"

...\winapi>gcc -c -m64 -O1 -DPSAPI_VERSION=1  -I"C:\Program Files (x86)\Cheat Engine 6.8.1\plugins" winapi.c

...\winapi>gcc -c -m64 -O1 -DPSAPI_VERSION=1  -I"C:\Program Files (x86)\Cheat Engine 6.8.1\plugins" wutils.c

...\winapi>gcc -Wl,-s -shared winapi.o wutils.o "C:\Program Files (x86)\Cheat Engine 6.8.1\plugins\lua53-64.lib" -lpsapi -lMpr -o winapi.dll


Errors :

Code:
'#' is not recognized as an internal or external command,
operable program or batch file.
winapi.l.c: In function 'l_window_from_handle':
winapi.l.c:405:29: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   return push_new_Window(L, (HWND)hwnd);
                             ^
winapi.o:winapi.c:(.text+0x13): undefined reference to `lua_newuserdata'
winapi.o:winapi.c:(.text+0x2a): undefined reference to `lua_getfield'
winapi.o:winapi.c:(.text+0x37): undefined reference to `lua_setmetatable'
winapi.o:winapi.c:(.text+0x5e): undefined reference to `lua_newuserdata'
winapi.o:winapi.c:(.text+0x75): undefined reference to `lua_getfield'
winapi.o:winapi.c:(.text+0x82): undefined reference to `lua_setmetatable'
winapi.o:winapi.c:(.text+0xc8): undefined reference to `luaL_checklstring'
... (375 undefined references total, non unique)
wutils.o:wutils.c:(.text+0x589): undefined reference to `lua_pushlstring'
collect2.exe: error: ld returned 1 exit status



I am able to find those symbols in lua53-64.lib, so I believe this is a linking issue.



Extra :

The undefined references go away when I remove the "-s" symbols flag, but the compilation still doesn't go through.

I tried using the compiler flags "-static", "-static-libgcc" and "-static-libstdc++" in the last gcc command of the compiling bat script.

Code:

set LUA_INCLUDE=C:\Program Files (x86)\Cheat Engine 6.8.1\plugins
set LUA_LIB=C:\Program Files (x86)\Cheat Engine 6.8.1\plugins\lua53-64.lib
set CFLAGS=-c -m64 -O1 -DPSAPI_VERSION=1  -I"%LUA_INCLUDE%"
gcc %CFLAGS% winapi.c
gcc %CFLAGS% wutils.c
gcc -Wl, -static-libgcc winapi.o wutils.o "%LUA_LIB%" -lpsapi -lMpr -o winapi.dll


I don't get undefined references, but this errror :

Code:
winapi.l.c: In function 'l_window_from_handle':
winapi.l.c:405:29: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   return push_new_Window(L, (HWND)hwnd);
                             ^
C:/Qt/Tools/mingw730_64/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find : Invalid argument
collect2.exe: error: ld returned 1 exit status
Back to top
View user's profile Send private message
NoobesGT
Cheater
Reputation: 0

Joined: 17 Dec 2018
Posts: 36

PostPosted: Fri Dec 28, 2018 4:40 am    Post subject: Reply with quote

use .lib
_________________
I hope you will know next time 1337
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites