Welcome! Log In Create A New Profile

Advanced

Compiling Lua

Posted by Glottis 
Compiling Lua
January 06, 2010 02:50PM
Hi all,

I'm a beginning coder and I'm trying to compile Lua, since I cant seem to find any pre-compiled version somewhere.
But can't get it to work. When I try make, as described at the wiibrew Lua page, I get the following output:

At first it seems it couldn't find the fat.h header, so I changed the makefile to include the path C:\devkitPro\libogc\

But now I get this:

...
lauxlib.c: In function 'luaL_loadfile':
lauxlib.c:553: warning: implicit declaration of function 'fatInitDefault'
make[2]: *** [lauxlib.o] Error 1
make[2]: Leaving directory '/c/luawii/lua/lua-5.1.3/src'
make[1]: *** [generic] Error 2
make[1]: Leaving directory '/c/luawii/lua/lua-5.1.3/src'
make: *** [generic] Error 2

Has anyone any suggestions?

thanks in advance.
Re: Compiling Lua
January 06, 2010 10:16PM
First off, thanks a lot for posting this. I'm a huge fan of lua and had no idea that this even existed. Now I have a new toy to play with :D

It compiled perfectly for me. You probably just didn't set-up your makefile correctly. Try using mine:
#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC")
endif

include $(DEVKITPPC)/wii_rules

#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
#---------------------------------------------------------------------------------
TARGET		:=	$(notdir $(CURDIR))
BUILD		:=	build
SOURCES		:=	source
DATA		:=	data  
INCLUDES	:=

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------

CFLAGS	= -g -O2 -Wall $(MACHDEP) $(INCLUDE)
CXXFLAGS	=	$(CFLAGS)

LDFLAGS	=	-g $(MACHDEP) -Wl,-Map,$(notdir $@).map

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS	:=	-lpng -lz -logc -lm

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS	:=

#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT	:=	$(CURDIR)/$(TARGET)

export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
					$(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR	:=	$(CURDIR)/$(BUILD)

#---------------------------------------------------------------------------------
# automatically build a list of object files for our project
#---------------------------------------------------------------------------------
CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
sFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
	export LD	:=	$(CC)
else
	export LD	:=	$(CXX)
endif

export OFILES	:=	$(addsuffix .o,$(BINFILES)) \
					$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
					$(sFILES:.s=.o) $(SFILES:.S=.o)

#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDE	:=	$(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \
					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
					-I$(CURDIR)/$(BUILD) \
					-I$(LIBOGC_INC)

#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
					-L$(LIBOGC_LIB)

export OUTPUT	:=	$(CURDIR)/$(TARGET)
.PHONY: $(BUILD) clean

#---------------------------------------------------------------------------------
$(BUILD):
	@[ -d $@ ] || mkdir -p $@
	@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
	@echo clean ...
	@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol
#---------------------------------------------------------------------------------

install:
	@mkdir -p lib
	@mkdir -p include
	@cp $(OUTPUT).a lib/libwiisprite.a
	@cp source/*.h include/
realinstall:
	@cp $(OUTPUT).a $(LIBOGC_LIB)/libwiisprite.a
	@cp source/*.h $(LIBOGC_INC)

#---------------------------------------------------------------------------------
run:
	wiiload $(TARGET).dol

#---------------------------------------------------------------------------------
%.a:
	@echo linking to lib ... $(notdir $@)
	@$(AR) -rc $@ $^
#---------------------------------------------------------------------------------
else

DEPENDS	:=	$(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).a: $(OFILES)

#---------------------------------------------------------------------------------
# This rule links in binary data with the .jpg extension
#---------------------------------------------------------------------------------
%.jpg.o	:	%.jpg
#---------------------------------------------------------------------------------
	@echo $(notdir $<)
	$(bin2o)

-include $(DEPENDS)

#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
Re: Compiling Lua
January 07, 2010 08:31AM
Thanks for your reply, I myself also thinks it really rocks to have Lua available on Wii!
But your makefile doesn't do the trick for me. I'm not sure if there is another version of Lua for Wii available, but I'm using the version found here: Lua for Wii.

I have devkitPPC r19 installed, together with libogc, which already comes with libfat.

When I follow the instructions in the README:

cd lua-5.1.3/
make
make install
cd ..
make
cp test.lua /mnt/to/your/sdcard
wiiload lua.elf

Basically that's all you have to do!

So first I have to compile Lua and then the example.

when I do this:
cd lua-5.1.3/
make

The output is this:
C:\lua>cd lua-5.1.3


C:\lua\lua-5.1.3>make
cd src && make generic
make[1]: Entering directory `/c/lua/lua-5.1.3/src'
make all MYCFLAGS=
make[2]: Entering directory `/c/lua/lua-5.1.3/src'
/c/devkitPro/devkitPPC/bin/powerpc-gekko-gcc -O2 -mrvl -Wall -DGEKKO -mrvl -mcpu
=750 -meabi -mhard-float -I/c/devkitPro/devkitPPC/include   -c -o lapi.o lapi.c
make[2]: /c/devkitPro/devkitPPC/bin/powerpc-gekko-gcc: Command not found
make[2]: *** [lapi.o] Error 127
make[2]: Leaving directory `/c/lua/lua-5.1.3/src'
make[1]: *** [generic] Error 2
make[1]: Leaving directory `/c/lua/lua-5.1.3/src'
make: *** [generic] Error 2

C:\lua\lua-5.1.3>

The problem here is the file /c/devkitPro/devkitPPC/bin/powerpc-gekko-gcc doesn't exist. To my knowledge it is an older name of the same thing, but due to compatibility reasons it was renamed in powerpc-eabi-gcc in release 18 of the devkit. I might be wrong at this, however.
So if I change line 12 in the makefile in `/c/lua/lua-5.1.3/src' form:

CC= $(DEVKITPPC)/bin/powerpc-gekko-gcc

in:
CC= $(DEVKITPPC)/bin/powerpc-eabi-gcc

and try to make, this is the output:

In file included from lauxlib.c:14:
c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-eabi/4.4.2/../../../../powerpc-eab
i/include/fat.h:38:25: error: ogc/disc_io.h: No such file or directory
In file included from lauxlib.c:14:
c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-eabi/4.4.2/../../../../powerpc-eab
i/include/fat.h:46: error: expected '=', ',', ';', 'asm' or '__attribute__' befo
re 'fatInit'
c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-eabi/4.4.2/../../../../powerpc-eab
i/include/fat.h:51: error: expected '=', ',', ';', 'asm' or '__attribute__' befo
re 'fatInitDefault'
c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-eabi/4.4.2/../../../../powerpc-eab
i/include/fat.h:59: error: expected '=', ',', ';', 'asm' or '__attribute__' befo
re 'fatMountSimple'
c:\devkitpro\devkitppc\bin\../lib/gcc/powerpc-eabi/4.4.2/../../../../powerpc-eab
i/include/fat.h:69: error: expected '=', ',', ';', 'asm' or '__attribute__' befo
re 'fatMount'
lauxlib.c: In function 'luaL_loadfile':
lauxlib.c:553: warning: implicit declaration of function 'fatInitDefault'
make[2]: *** [lauxlib.o] Error 1
make[2]: Leaving directory `/c/lua/lua-5.1.3/src'
make[1]: *** [generic] Error 2
make[1]: Leaving directory `/c/lua/lua-5.1.3/src'
make: *** [generic] Error 2

C:\lua\lua-5.1.3>

Now I have fat.h in C:\devkitPro\libogc\include
and libfat.a in C:\devkitPro\libogc\lib\wii
Also in lauxlib.c is fat.h listed as include, as it should be.
The LIBS line of the makefile in C:\lua\lua-5.1.3\src reads:

LIBS=$(MACHDEP) -mrvl -L$(DEVKITPPC)/lib/wii -lfat -lwiiuse -lbte -logc -lm

But still it seems it can't find libfat for some reason.

Which version did you use to compile Lua? Is there anywhere I can find a precompiled version of it, so I can still make use of it?
Re: Compiling Lua
January 07, 2010 12:32PM
I had the exact same problem until I replaced their makefile with mine. Then everything was fine. If you're interested, I can post my compilation for you.
Re: Compiling Lua
January 07, 2010 03:20PM
If you can post your compiled version, it that will be very much helpfull.
But if your makefile worked for you, I can't understand why it doesn't for me.

First I tried to replace the makefile in C:\lua\lua-5.1.3

with the one you posted, and it will compile without any errors, this is the result:
C:\lua\lua-5.1.3>make
lua-5.1.3.a

C:\lua\lua-5.1.3>

So I get some result now
I tried to rename it to liblua.a and place it in C:\devkitPro\libogc\lib\wii and copy the *.h files in C:\lua\lua-5.1.3\src to C:\devkitPro\libogc\include, to be able to compile the example in C:\lua. But it seems not to be able to find the functions:

C:\lua>make
main.c
c:/lua/source/main.c: In function 'main':
c:/lua/source/main.c:47: warning: suggest parentheses around operand of '!' or c
hange '&' to '&&' or '!' to '~'
c:/lua/source/main.c:55: warning: suggest parentheses around operand of '!' or c
hange '&' to '&&' or '!' to '~'
c:/lua/source/main.c:77: warning: implicit declaration of function 'sleep'
linking ... lua.elf
main.o: In function `main':
c:/lua/source/main.c:43: undefined reference to `luaL_newstate'
c:/lua/source/main.c:51: undefined reference to `luaL_openlibs'
c:/lua/source/main.c:52: undefined reference to `luaL_loadfile'
c:/lua/source/main.c:60: undefined reference to `lua_pcall'
c:/lua/source/main.c:69: undefined reference to `lua_getfield'
c:/lua/source/main.c:70: undefined reference to `lua_pcall'
c:/lua/source/main.c:43: undefined reference to `luaL_newstate'
c:/lua/source/main.c:73: undefined reference to `lua_tolstring'
collect2: ld returned 1 exit status
make[1]: *** [/c/lua/lua.elf] Error 1
make: *** [build] Error 2

C:\lua>
Re: Compiling Lua
January 26, 2010 01:26PM
Would also like to know how to compile this.
Did exactly like the wiki told me to, and it is failing.

The main problem is, it can't find -lfat using the makefile provided. (after you change "gekko" into "eabi")

Arikado, have you actually got your library to compile the provided example? If so, please explain all the steps you took.

EDIT: Thought it was in Off-Topic...



Edited 1 time(s). Last edit at 01/26/2010 01:28PM by Ksmiler.
Re: Compiling Lua
January 26, 2010 04:33PM
Here's my compiled build of the library: [www.mediafire.com]

Dont forget to install it correctly and install the headers correctly before trying to compile anything that uses it.
Re: Compiling Lua
January 26, 2010 09:36PM
i think that makefile is broken akirado
install:
	@mkdir -p lib
	@mkdir -p include
	@cp $(OUTPUT).a lib/libwiisprite.a
	@cp source/*.h include/
realinstall:
	@cp $(OUTPUT).a $(LIBOGC_LIB)/libwiisprite.a
	@cp source/*.h $(LIBOGC_INC)
Re: Compiling Lua
January 27, 2010 12:43AM
xD Apparently. Worst part is that's the makefile I use to build tons of static libraries (which work btw).

Nice catch.



Edited 1 time(s). Last edit at 01/27/2010 12:43AM by Arikado.
Sorry, only registered users may post in this forum.

Click here to login