Hello,
I am trying to compile a basic SDL2 program using the SDL2 libraries installed by devKitpro's pacman. When I compile it, I get the following error which i can't figure out:
Has anyone experienced this before or know a dirrection to point me in? I wonder if it is something in my Makefile, I am not good at understanding these Makefiles:
Here is the main code itself:
I am trying to compile a basic SDL2 program using the SDL2 libraries installed by devKitpro's pacman. When I compile it, I get the following error which i can't figure out:
linking ... sdl-display-image.elf/opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/15.1.0/../../../../powerpc-eabi/bin/ld: /opt/devkitpro/devkitPPC/bin/../lib/gcc/powerpc-eabi/15.1.0/../../../../powerpc-eabi/lib/crtmain.o: in function `__crtmain':crtmain.c:(.text.__crtmain+0x38): undefined reference to `main'collect2: error: ld returned 1 exit statusmake[1]: *** [/opt/devkitpro/devkitPPC/wii_rules:31: /home/dcole/Documents/wii_dev/sdl-display-image/sdl-display-image.elf] Error 1make: *** [Makefile:101: build] Error 2Has anyone experienced this before or know a dirrection to point me in? I wonder if it is something in my Makefile, I am not good at understanding these Makefiles:
#---------------------------------------------------------------------------------# Clear the implicit built in rules#---------------------------------------------------------------------------------.SUFFIXES:#---------------------------------------------------------------------------------ifeq ($(strip $(DEVKITPPC)),)$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")endifinclude $(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 := buildSOURCES := sourceDATA := dataINCLUDES :=#---------------------------------------------------------------------------------# 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 := -lSDL2 -lwiiuse -lbte -logc -lm#---------------------------------------------------------------------------------# list of directories containing libraries, this must be the top level containing# include and lib#---------------------------------------------------------------------------------LIBDIRS := $(DEVKITPRO)/portlibs/wii#---------------------------------------------------------------------------------# 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)endifexport OFILES_BIN := $(addsuffix .o,$(BINFILES))export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))#---------------------------------------------------------------------------------# 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 := -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/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: wiiload $(TARGET).dol#---------------------------------------------------------------------------------elseDEPENDS := $(OFILES:.o=.d)#---------------------------------------------------------------------------------# main targets#---------------------------------------------------------------------------------$(OUTPUT).dol: $(OUTPUT).elf$(OUTPUT).elf: $(OFILES)$(OFILES_SOURCES) : $(HFILES)#---------------------------------------------------------------------------------# This rule links in binary data with the .jpg extension#---------------------------------------------------------------------------------%.jpg.o %_jpg.h : %.jpg#--------------------------------------------------------------------------------- @echo $(notdir $<) $(bin2o)-include $(DEPENDS)#---------------------------------------------------------------------------------endif#---------------------------------------------------------------------------------Here is the main code itself:
#include <wiiuse/wpad.h> #include "SDL2/SDL.h"#include "SDL2/SDL_image.h"int main(int argc, char* argv[]) { WPAD_Init(); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) { //std::cout << "Error SDL2 Initialization : " << SDL_GetError(); return 1; } if (IMG_Init(IMG_INIT_PNG) == 0) { //std::cout << "Error SDL2_image Initialization"; return 2; } SDL_Window* window = SDL_CreateWindow("First program", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_OPENGL); if (window == NULL) { //std::cout << "Error window creation"; return 3; } SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); if (renderer == NULL) { //std::cout << "Error renderer creation"; return 4; } SDL_Surface* lettuce_sur = IMG_Load("lettuce.png"); if (lettuce_sur == NULL) { //std::cout << "Error loading image: " << IMG_GetError(); return 5; } SDL_Texture* lettuce_tex = SDL_CreateTextureFromSurface(renderer, lettuce_sur); if (lettuce_tex == NULL) { //std::cout << "Error creating texture"; return 6; } SDL_FreeSurface(lettuce_sur); bool done = false; while (!done){ // scans if a button was pressed WPAD_ScanPads(); u32 held = WPAD_ButtonsHeld(0); // if the homebutton is pressed it will set done = true and it will fill the screen // with a black background if(held & WPAD_BUTTON_HOME){ done = true; } } SDL_RenderClear(renderer); SDL_RenderCopy(renderer, lettuce_tex, NULL, NULL); SDL_RenderPresent(renderer); SDL_DestroyTexture(lettuce_tex); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); IMG_Quit(); SDL_Quit(); return 0;}







