Coding with Eclipse tutorial

support for the powerpc toolchain
Post Reply
laserbeak43
Posts: 10
Joined: Thu Jul 29, 2010 6:42 am

Coding with Eclipse tutorial

Post by laserbeak43 » Sat Jul 31, 2010 11:16 pm

Hello,
I've taken a tutorial to set Eclipse up for wiidev. And it worked fine, but as soon as i tried wiisprite, a problem arose. I get an error saying:

Code: Select all

c:/devkitpro/devkitppc/bin/../lib/gcc/powerpc-eabi/4.4.3/../../../../powerpc-eabi/bin/ld.exe: cannot find -lwiisprite
does this mean that it's trying to look for libwiisprite.a?
for anyone interested, here's my makefile

Code: Select all

#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>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
INCLUDES	:=	include
DATA 		:=	data

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

CFLAGS	= -g -O2 -Wall $(MACHDEP) $(INCLUDE) -I(DEVKITPPC)/local/include
CXXFLAGS	=	$(CFLAGS)

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

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS	:=	-lwiisprite	-lpng	-lz	-lwiiuse	-lbte	-lfat	-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),-I$(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) -L$(DEVKITPPC)/local/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

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

#---------------------------------------------------------------------------------
else

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

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).dol: $(OUTPUT).elf
$(OUTPUT).elf: $(OFILES)

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

-include $(DEPENDS)

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

-include $(DEPENDS)

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

-include $(DEPENDS)

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

%.mod.o	:	%.mod
#---------------------------------------------------------------------------------
	@echo $(notdir $<)
	@$(bin2o)

-include $(DEPENDS)

#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
and my.cpp

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <gccore.h>
#include <wiiuse/wpad.h>
#include <fat.h>
#include "board_jpg.h"
#include "Green00_jpg.h"
#include "Green01_jpg.h"
#include "Green02_jpg.h"
#include "Green10_jpg.h"
#include "Green11_jpg.h"
#include "Green12_jpg.h"
#include "Green20_jpg.h"
#include "Green21_jpg.h"
#include "Green22_jpg.h"
#include "Pink00_jpg.h"
#include "Pink01_jpg.h"
#include "Pink02_jpg.h"
#include "Pink10_jpg.h"
#include "Pink11_jpg.h"
#include "Pink12_jpg.h"
#include "Pink20_jpg.h"
#include "Pink21_jpg.h"
#include "Pink22_jpg.h"

#include <wiisprite.h> // The main libwiisprite header.
using namespace wsp; // To not make us type this again and again

//#include <libwiisprite.h> // This is the header file we got from the devkitPPC tool "raw2c"
 
int main(int argc, char **argv)
{
	// Create the game window and initalise the VIDEO subsystem
	GameWindow gwd;
	gwd.InitVideo();

	gwd.SetBackground((GXColor){ 255, 255, 255, 255 });

	LayerManager manager(5);

	//load images
	Image bg;
	Image g00, p00;
	Image g01, p01;
	Image g02, p02;
	Image g10, p10;
	Image g11, p11;
	Image g12, p12;
	Image g20, p20;
	Image g21, p21;
	Image g22, p22;

	Sprite sprites[] ={sbg, sg00, sp00, sg01, sp01, sg02, sp02, sg10, sp10, sg11,
				sp11, sg12, sp12, sg20, sp20, sg21, sp21, sg22, sp22};

	/*Sprite sbg, sg00, sp00, sg01, sp01, sg02, sp02, sg10, sp10, sg11,
		sp11, sg12, sp12, sg20, sp20, sg21, sp21, sg22, sp22;*/

	if( bg.LoadImage(board) != IMG_LOAD_ERROR_NONE)exit(0);
	if( g00.LoadImage(Green00) != IMG_LOAD_ERROR_NONE)exit(0);
	if( g01.LoadImage(Green01) != IMG_LOAD_ERROR_NONE)exit(0);
	if( g02.LoadImage(Green02) != IMG_LOAD_ERROR_NONE)exit(0);
	if( g10.LoadImage(Green10) != IMG_LOAD_ERROR_NONE)exit(0);
	if( g11.LoadImage(Green11) != IMG_LOAD_ERROR_NONE)exit(0);
	if( g12.LoadImage(Green12) != IMG_LOAD_ERROR_NONE)exit(0);
	if( g20.LoadImage(Green20) != IMG_LOAD_ERROR_NONE)exit(0);
	if( g21.LoadImage(Green21) != IMG_LOAD_ERROR_NONE)exit(0);
	if( g22.LoadImage(Green22) != IMG_LOAD_ERROR_NONE)exit(0);

	if( p00.LoadImage(Pink00) != IMG_LOAD_ERROR_NONE)exit(0);
	if( p01.LoadImage(Pink01) != IMG_LOAD_ERROR_NONE)exit(0);
	if( p02.LoadImage(Pink02) != IMG_LOAD_ERROR_NONE)exit(0);
	if( p10.LoadImage(Pink10) != IMG_LOAD_ERROR_NONE)exit(0);
	if( p11.LoadImage(Pink11) != IMG_LOAD_ERROR_NONE)exit(0);
	if( p12.LoadImage(Pink12) != IMG_LOAD_ERROR_NONE)exit(0);
	if( p20.LoadImage(Pink20) != IMG_LOAD_ERROR_NONE)exit(0);
	if( p21.LoadImage(Pink21) != IMG_LOAD_ERROR_NONE)exit(0);
	if( p22.LoadImage(Pink22) != IMG_LOAD_ERROR_NONE)exit(0);

	sbg.SetImage(&bg);
	sbg.SetPosition(0,0);
	sg00.SetImage(&g00);
	sg00.SetPosition(106.75, 80.5);
	sp00.SetImage(&p00);
	sp00.SetPosition(106.75, 80.5);
	sg01.SetImage(&g01);
	sg01.SetPosition(319.83, 80.5);
	sp01.SetImage(&p01);
	sp01.SetPosition(319.83, 80.5);
	sg02.SetImage(&g02);
	sg02.SetPosition(523.83, 80.17);
	sp02.SetImage(&p02);
	sp02.SetPosition(523.83, 80.17);
	sg10.SetImage(&g10);
	sg10.SetPosition(107.17, 241.17);
	sp10.SetImage(&p10);
	sp10.SetPosition(107.17, 241.17);
	sg11.SetImage(&g11);
	sg11.SetPosition(320.29, 241.33);
	sp11.SetImage(&p11);
	sp11.SetPosition(320.29, 241.33);
	sg12.SetImage(&g12);
	sg12.SetPosition(532.96, 241.17);
	sp12.SetImage(&p12);
	sp12.SetPosition(532.96, 241.17);
	sg20.SetImage(&g20);
	sg20.SetPosition(107.46, 399.83);
	sp20.SetImage(&p20);
	sp20.SetPosition(107.46, 399.83);
	sg21.SetImage(&g21);
	sg21.SetPosition(320.13, 399.75);
	sp21.SetImage(&p21);
	sp21.SetPosition(320.13, 399.75);
	sg22.SetImage(&g22);
	sg22.SetPosition(532.92, 400.04);
	sp22.SetImage(&p22);
	sp22.SetPosition(532.92, 400.04);


	// Initialise Wiimote
	WPAD_Init();
 
	for(;;)
	{
		WPAD_ScanPads();
		if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_HOME)
			break;
		gwd.Flush();
	}
	return 0;
}
would really appreciate your help.

Thanks

WinterMute
Site Admin
Posts: 1861
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Coding with Eclipse tutorial

Post by WinterMute » Sun Aug 01, 2010 12:32 pm

I've edited your post to add the makefile & cpp files to the post inside code tags. Even if you set the paste to never expire there's still no guarantee that the paste site will still be there next week.

Yes, it means it's looking for libwiisprite.a and obviously hasn't found it.

In your makefile I see you've added -L$(DEVKITPPC)/local/lib to LIBPATHS which isn't the best of ideas. The windows installer deletes the entire $(DEVKITPPC) folder when updating the toolchain in order to avoid the buildup of cruft. What I would suggest doing in preference is to add a $(DEVKITPRO)/wiilibs folder which will contain include & lib folders for libraries not distributed by devkitPro and adding $(DEVKITPRO)/wiilibs to LIBDIRS instead. You should then place the headers for libwiisprite in $(DEVKITPRO)/wiilibs/include and the .a files in $(DEVKITPRO)/wiilibs/lib - hopefully the libwiisprite library is constructed properly with these folders already.

In your code you have using namespace wsp; at file scope which isn't really a good idea either. Namespaces are used to prevent pollution of the global namespace and avoid conflicts so, if you're going to do that, you might as well not use namespaces at all. It's much better practice to place using namespace directives at function scope in the places where you're using the definitions in that namespace.

Apart from that things look fine - assuming you place libwiisprite.a in one of the searched library paths and use the custom Makefile with Eclipse i don't see why it would fail. Ideally that should probably be $(DEVKITPRO)/wiilibs/lib.
Help keep devkitPro toolchains free, Donate today

Personal Blog

laserbeak43
Posts: 10
Joined: Thu Jul 29, 2010 6:42 am

Re: Coding with Eclipse tutorial

Post by laserbeak43 » Sun Aug 01, 2010 9:43 pm

Thanks for the namespace advice, I'll look into that. As for the the directories, even though it might not be seen as a good idea to put the libwiisprite source and libs in with the devkitpro install, it's how i've left it for now. I've had lots of trouble getting a setup up and running and would just like a bit of gratification. I'll clean it up after that :)

so i've changed my make file to look like this:

Code: Select all

export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
					-L$(LIBOGC_LIB) $(DEVKITPRO)/libogc/lib
and i get the error:
c:/devkitpro/devkitppc/bin/../lib/gcc/powerpc-eabi/4.4.3/../../../../powerpc-eabi/bin/ld.exe: c:/devkitPro/libogc/lib: No such file: Permission denied
does this mean i need elevation? I've set eclipse to run as admin just now, but that hasn't changed anything.

-edit-
Ok so i switched it to -L$(DEVKITPRO)/libogc/lib and now i get the error:
c:/devkitpro/devkitppc/bin/../lib/gcc/powerpc-eabi/4.4.3/../../../../powerpc-eabi/lib/crtmain.o: In function `__crtmain':
c:/Users/davem/projects/devkitpro/buildscripts/newlib-1.18.0/libgloss/rs6000/crtmain.c:18: undefined reference to `main'
i have no users named davem..

WinterMute
Site Admin
Posts: 1861
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Coding with Eclipse tutorial

Post by WinterMute » Sun Aug 01, 2010 11:31 pm

laserbeak43 wrote: so i've changed my make file to look like this:

Code: Select all

export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
					-L$(LIBOGC_LIB) -L$(DEVKITPRO)/libogc/lib
What I meant was:

Code: Select all

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS	:=	$(DEVKITPRO)/wiilibs
Ok so i switched it to -L$(DEVKITPRO)/libogc/lib and now i get the error:
c:/devkitpro/devkitppc/bin/../lib/gcc/powerpc-eabi/4.4.3/../../../../powerpc-eabi/lib/crtmain.o: In function `__crtmain':
c:/Users/davem/projects/devkitpro/buildscripts/newlib-1.18.0/libgloss/rs6000/crtmain.c:18: undefined reference to `main'
i have no users named davem..
That's just the error message including the path of the source file from where newlib was built, i.e. on my machine.

The Makefiles pick up source files from the directories listed in sources, at the top.

Code: Select all

SOURCES		:=	source
That error message means you probably haven't put your source files in the source directory or possibly that you don't have a main function.
Help keep devkitPro toolchains free, Donate today

Personal Blog

laserbeak43
Posts: 10
Joined: Thu Jul 29, 2010 6:42 am

Re: Coding with Eclipse tutorial

Post by laserbeak43 » Mon Aug 02, 2010 3:14 am

sorry about the late reply,
you're right, i don't have a source folder. My project's directory looks like this

Code: Select all

+project/
	+build/
	+data/
		all of the images along with the .o and .h files generated with bin2o
main.cpp
Makefile
should i make a dir named source and put main in there? what about the .h files generated by bin2o? leave those there or put them in the includes directory? or do i just delete that SOURCES entry from the makefile?

Thanks

-edit-
ok now im completely lost without a clue. I put the main file in the sources folder and rebuilt and got

Code: Select all

/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `powerpc-eabi-g++ -MMD -MP -MF /c/Users/Laserbeak43/Wiiworkspace/tictactoe/build/main.d -g -O2 -Wall -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float -I/c/Users/Laserbeak43/Wiiworkspace/tictactoe/include -I/c/devkitPro/libogc/libs/include -I/c/Users/Laserbeak43/Wiiworkspace/tictactoe/build -I/c/devkitPro/libogc/include -I(DEVKITPPC)/local/include -c /c/Users/Laserbeak43/Wiiworkspace/tictactoe/source/main.cpp -o main.o '
make[1]: *** [main.o] Error 2
make: *** [build] Error 2
-edit-
changed this: I(DEVKITPPC)/local/include
to I$(DEVKITPPC)/local/include
and all i have now are .cpp errors :)

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests