lua-users home
lua-l archive

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


I am using Ubuntu but I've been having problems first compiling my C
project that uses LUA and then I found a way that it compiles but
crashes when run. It compiled and worked fine on Fedora and Windows 7
using MinGW with all of these tries.

I use this Makefile. If it doesn't have both -llua5.1 and -llua it
usually generates even more errors.
CC = gcc
CFLAGS = -Wall -g -O0 -lSDL -lSDL_image -lSDL_ttf -llua5.1 -llua
tom: src/tom.c
	$(CC) src/tom.c $(CFLAGS) $(FLAGS) -o tom

Using this code:

	lua_State* L;
	L = luaL_newstate();
	luaL_openlibs(L);

it gives these warnings:

src/tom.c: In function ‘main’:
src/tom.c:486: warning: implicit declaration of function ‘luaL_newstate’
src/tom.c:486: warning: assignment makes pointer from integer without a cast
src/tom.c:487: warning: implicit declaration of function ‘luaL_openlibs’

and the program crashes when run. Using this code:

	lua_State* L;
	L = lua_open();
	lua_pushcfunction(L, luaopen_base); lua_call(L, 0, 0);
	lua_pushcfunction(L, luaopen_string); lua_call(L, 0, 0);
	lua_pushcfunction(L, luaopen_table); lua_call(L, 0, 0);
	lua_pushcfunction(L, luaopen_math); lua_call(L, 0, 0);
	lua_pushcfunction(L, luaopen_io); lua_call(L, 0, 0);

it compiles but crashes when I try to run it. gdb says:

Program received signal SIGSEGV, Segmentation fault.
0x0804be28 in lua_pushvalue ()
(gdb) bt
#0  0x0804be28 in lua_pushvalue ()
#1  0x0020415d in luaopen_base () from /usr/lib/liblua5.1.so.0
#2  0x0804e976 in luaD_precall ()
#3  0x0804edb1 in luaD_call ()
#4  0x0804b4cb in main (argc=1, argv=0xbffff7e4) at src/tom.c:487

On line 487 there's this: lua_pushcfunction(L, luaopen_base); lua_call(L, 0, 0);

The "lua -v" command states that its version is 5.0 but I clearly have
LUA 5.1 also installed:
i   lua50                                                          -
Small embeddable language with simple procedural syntax
i   lua50-doc                                                      -
Documentation for the Lua 5.0 programming language
i   lua5.1                                                         -
Simple, extensible, embeddable programming language
iB  libtolua-dev                                                   -
Tool to integrate C/C++ code with Lua - development files
c   libtolua0                                                      -
Tool to integrate C/C++ code with Lua - runtime libraries
v   lua                                                            -
i A liblualib50                                                    -
Extension library for the Lua 5.0 programming language
i   liblualib50-dev                                                -
Extension library for Lua 5.0: static and headers
c   liblualib40                                                    -
Extension library for the Lua 4.0 programming language
i A liblua50                                                       -
Main interpreter library for the Lua 5.0 programming language
i A liblua50-dev                                                   -
Main interpreter library for Lua 5.0: static library and headers
v   liblua5.1-sql-sqlite-dev                                       -
v   liblua5.1-sql-sqlite2                                          -
v   liblua5.1-sql-mysql2                                           -
i   liblua5.1-curl-dev                                             -
libcURL development files for the lua language version 5.1
i A liblua5.1-curl0                                                -
libcURL bindings for the lua language version 5.1
v   liblua5.1-dev                                                  -
idA liblua5.1-0                                                    -
Simple, extensible, embeddable programming language
p   liblua5.1-0-dbg                                                -
Simple, extensible, embeddable programming language
id  liblua5.1-0-dev                                                -
Simple, extensible, embeddable programming language

And "gcc -v" states: gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9)

In case you need the full source for my project, it's available here:
mandicor.net/tom/tom.zip