NO

Author Topic: Compiling LUA scripting language  (Read 15980 times)

Fuzzlix

  • Guest
Compiling LUA scripting language
« on: May 29, 2013, 03:51:41 PM »
Hi.
I am allmost new to pelles c. I did some simple console programs in pelles c long time ago. But i am still a beginner in c.

Now i tried to compile the newest lua sources to get a simple lua interpreter running. (using PellesC/64bit)
sources at http://www.lua.org/ftp/lua-5.2.2.tar.gz

1st i tried to compile the lua dll:
- new project: dll64
- inserted all c-files to the project (except lua.c & luac.c)
  ok (with options/compiler/use_ms_extensions=on)
  switching options/compiler/use_ms_extensions=off results in a error:
Code: [Select]
C:\Program Files\PellesC\Include\Win\winnt.h(559): fatal error #1014: #error: "No target architecture".  Why?

so i kept options/compiler/use_ms_extensions=on and i got a compiled dll file without errors.

next step: try to make the lua.exe file:
- new project: win64 console app
- added lua.c as sourcefile
- same compiler options as for the dll:options/compiler/use_ms_extensions=on
Code: [Select]
d:\Pelles C Projects\lua522\lua.c(178): warning #2145: Assignment of 'void __fastcall function(int)' to 'void __cdecl function(int)'.
d:\Pelles C Projects\lua522\lua.c(480): warning #2203: Function 'main' can't be __fastcall, changed to __cdecl.
- switching options/compiler/use_ms_extensions=off eliminites those 2 warnings but my exe cant probably load the dll ?

And i got many unresolved external symbols defined in the dll. How to link the dll-infos into my exe-project?

i tried to compile the lua-interpreter statically into my exe. I got errors too. I dont know it is possible without hacking the orginal lua source files)

Thanks a lot for your help.


Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Compiling LUA scripting language
« Reply #1 on: May 29, 2013, 05:33:23 PM »
For dll remember to define LUA_BUILD_AS_DLL for exports.
May the source be with you

Fuzzlix

  • Guest
Re: Compiling LUA scripting language
« Reply #2 on: May 29, 2013, 05:39:44 PM »
Thanks a LOT!

My exe is compiled and running  :)

Fuzzlix.

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: Compiling LUA scripting language
« Reply #3 on: May 30, 2013, 01:33:48 AM »
Thanks a LOT!

My exe is compiled and running  :)

Fuzzlix.
Would you mind making the resulting project files available?

Ralf

Fuzzlix

  • Guest
Re: Compiling LUA scripting language
« Reply #4 on: May 30, 2013, 02:17:27 AM »
Would you mind making the resulting project files available?
Shure!

Ok, i am using PellesC 7.0 /64bit.
- copy all files from http://www.lua.org/ftp/lua-5.2.2.tar.gz into a new folder.
- copy my 3 project files into the same folder.
- build lua522dll (dll-lib) or lua522lib (static lib)
- build lua

you are done. :)

Fuzzlix

  • Guest
Re: Compiling LUA scripting language
« Reply #5 on: May 30, 2013, 02:29:48 AM »
One more Question:
The orginal lua.exe has a nice blue icon. Is it possible to attach a custom icon to my console app using PellesC ?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Compiling LUA scripting language
« Reply #6 on: May 30, 2013, 05:39:15 AM »
One more Question:
The orginal lua.exe has a nice blue icon. Is it possible to attach a custom icon to my console app using PellesC ?
with resource file.
« Last Edit: May 30, 2013, 06:00:32 AM by timovjl »
May the source be with you

Fuzzlix

  • Guest
Re: Compiling LUA scripting language
« Reply #7 on: May 30, 2013, 07:26:59 AM »
with resource file.
Thank you. It is working :)

Fuzzlix.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: Compiling LUA scripting language
« Reply #8 on: May 30, 2013, 10:04:50 AM »
Works only for 64 bits because the calling convention is unique (__fastcall).
For 32 bits you have to hack header files adding __stdcall to all functions (you have to modify also some source files as lua.c and luac.c adding calling convention for some functions locally).
Optionally you can force calling convention for dll project to __cdecl (EDITED) so you don't have to change files, but there will be problems if you try to link the dll against something else than a console application.
« Last Edit: May 30, 2013, 01:50:36 PM by frankie »
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

Fuzzlix

  • Guest
Re: Compiling LUA scripting language
« Reply #9 on: May 30, 2013, 10:39:02 AM »
You are right.

I createt new project files from scratch for win32. No changes nessesary in the c source files. I attached all 6 project files AND the res files (by timovjl).

czerny

  • Guest
Re: Compiling LUA scripting language
« Reply #10 on: May 30, 2013, 05:09:21 PM »
I createt new project ...
The export library and the static library have same name.

Fuzzlix

  • Guest
Re: Compiling LUA scripting language
« Reply #11 on: May 30, 2013, 05:20:47 PM »
The export library and the static library have same name.
True!
But this sould not be a issue. For instance i want to build lua.exe in w32 and w64 version:
- i build lua522lib_32
- i build luaexe_32
- i copy lua.exe to somwhere ( it is not named lua32.exe or somewhat else)
- i build lua522lib_64
- i build luaexe_64
- i copy lua.exe to somwhere ( it is not named lua64.exe or somewhat else)

Within 3 minutes you have built both static linked versions of lua.exe

The dll projects shows that is possible to built the dlls. The orginal dll names are different to my dll names anyway. So you may want to change them.

Fuzzlix.

EDIT:
Ok, if you want to keep all libs and exe in the project tree, we need to define a directory structure for the files made. So what is your sugestion?
« Last Edit: May 30, 2013, 06:14:56 PM by Fuzzlix »

czerny

  • Guest
Re: Compiling LUA scripting language
« Reply #12 on: May 30, 2013, 06:50:44 PM »
If anyone wants to compile the whole lua archive (btw. luac is missing) she or he should include all the project files in a workspace (ppw)
and if you build the workspace, the first lib overwrites the second.

I (and most other users I suppose) have their private lib and include directories where the produced files and header files should be copied. You can do this automatically in the build process. They should be renamed in this stage at the latest.

Reading the documentation it seems to me, that the static be named liblua52.lib and the dll lua52.dll.



Fuzzlix

  • Guest
Re: Compiling LUA scripting language
« Reply #13 on: May 30, 2013, 07:02:38 PM »
Ok. i see. Give me some time ... :)

Fuzzlix

  • Guest
Re: Compiling LUA scripting language
« Reply #14 on: May 30, 2013, 09:11:41 PM »
Wow, this was a good trainig!  :)

I redid all the projects using different folders for temp files and output files.
I placed the workspace files in the project root and the project files in the .\src folder.
Now you have 2 workspaces - one for w32 and one for w64. Putting w32 and w64 into one workspace didnt look nice because you see all project names twice.

Please unzip the attached zip file into the project root folder.

I hope it looks better now. :)

Fuzzlix.