lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello All,

Could someone help me make out why I can't compile the foo.c spitted out by Steven lua2c app?

rmicro@ubuntu:~/lua_world$ gcc -O2 -Wall -I/usr/include/lua5.1 -fPIC foo.c
foo.c: In function ‘luaopen_foo’:
foo.c:18:5: warning: value computed is not used [-Wunused-value]
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 10
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 10
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 20 has invalid symbol index 19
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
/tmp/ccABERic.o: In function `luaopen_foo':
foo.c:(.text+0xc): undefined reference to `luaL_loadstring'
foo.c:(.text+0x21): undefined reference to `lua_pcall'
collect2: ld returned 1 exit status
rmicro@ubuntu:~/lua_world$ 

Regrads,
Emeka

On Sat, May 26, 2012 at 1:54 AM, Hallison Batista <hallison.batista@gmail.com> wrote:
Emeka,

If you want compile using the GCC and if you are using a Linux distribution, try these flags:

gcc -O2 -Wall -I/usr/include/lua5.1 -fPIC <file.c>

I hope this helps.

Att.

On Friday, May 25, 2012, Emeka wrote:
Hello Hallison,

I was not able to compile the out C file.

I will need to know the flags and paths to include.

Regards,\Emeka


On Wed, May 23, 2012 at 8:33 AM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> And that's to embed the source directly in a C file, as a properly
> escaped multiline C string, which is then loaded.

And, due to popular demand, a simple script for converting a Lua
module into a loadable C module.

https://gist.github.com/2787105

foo.c is the result of 'lua2c foo', with foo.lua looking like this:

module 'foo'

function answer()
       return 42
end

However, there is a problem when the module starts 'module(...)' since
luaL_loadstring does not compile the chunk correctly for this case.

I tested this on ml.lua, which is about 782 lines; lua2c strips
comments and leading space, so the final output is about 500 lines.
The compiled C extension is a bit smaller than the original Lua file;
another comparison is that it's a 18K dll versus 23K .luac file.

To test packages, I put ml.lua in a directory libs, and then said
'lua2c libs.ml', which resulted in libs_ml.c in the current directory,
and libs/ml.dll.

This should work fine for Lua 5.2 as well

And there's always yet another method; use squsih/soar to get all your
Lua files into one archive, and glue that to a Lua executable with
srlua.  (that's basically the rationale behind LuaBuild)

steve d.




--
Satajanus  Nig. Ltd





--
Hallison Batista
hallison.batista@gmail.com




--
Satajanus  Nig. Ltd