Compiling LUA scripting language

Started by Fuzzlix, May 29, 2013, 03:51:41 PM

Previous topic - Next topic

Fuzzlix

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:
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
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.


TimoVJL

For dll remember to define LUA_BUILD_AS_DLL for exports.
May the source be with you

Fuzzlix

Thanks a LOT!

My exe is compiled and running  :)

Fuzzlix.

Bitbeisser

Quote from: Fuzzlix on May 29, 2013, 05:39:44 PM
Thanks a LOT!

My exe is compiled and running  :)

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

Ralf

Fuzzlix

Quote from: Bitbeisser on May 30, 2013, 01:33:48 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

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 ?

TimoVJL

#6
Quote from: Fuzzlix 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 ?
with resource file.
May the source be with you

Fuzzlix


frankie

#8
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.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Fuzzlix

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

Quote from: Fuzzlix on May 30, 2013, 10:39:02 AM
I createt new project ...
The export library and the static library have same name.

Fuzzlix

#11
Quote from: czerny on May 30, 2013, 05:09:21 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?

czerny

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


Fuzzlix

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.