Page 1 of 1

SDL: Linker Errors when using SDL_mixer

Posted: Tue Apr 14, 2020 4:26 am
by JT21
Hello, I'm trying my hand at porting to the 3ds, specifically Chocolate Doom, and I've gotten a great deal through it when I came across an issue while trying to link the code. Any functions related to SDL_mixer result in an "undefined reference to x" error. I have attatched the relevant parts of my makefile and here is the log below (cut down since I've been marked as spam when trying to post this), along with some unrelated linker errors I have yet to fix. Thank you for any help!

Code: Select all

TARGET		:=	$(notdir $(CURDIR))
BUILD		:=	build
SOURCES		:=	src opl src/doom src/SDL2
DATA		:=	data
INCLUDES	:=	src textscreen pcsound opl codeblocks src/SDL2
GRAPHICS	:=	gfx

GFXBUILD	:=	$(BUILD)
ROMFS		:=	romfs
#GFXBUILD	:=	$(ROMFS)/gfx

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH	:=	-march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft

CFLAGS	:=	-g -Wall -O2 -mword-relocations \
			-fomit-frame-pointer -ffunction-sections \
			$(ARCH)

CFLAGS	+=	$(INCLUDE) -DARM11 -D_3DS

CXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11

ASFLAGS	:=	-g $(ARCH)
LDFLAGS	=	-specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)

LIBS	:= -lSDL_mixer -lSDL  -lcitro3d -lctru -lm

Code: Select all

c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: C:/devkitPro/portlibs/3ds/lib\libSDL_mixer.a(mixer.o): in function `mix_channels':
mixer.c:(.text.mix_channels+0x18c): undefined reference to `SDL_MixAudio'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: mixer.c:(.text.mix_channels+0x250): undefined reference to `SDL_MixAudio'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: C:/devkitPro/portlibs/3ds/lib\libSDL_mixer.a(music.o): in function `Mix_LoadMUS':
music.c:(.text.Mix_LoadMUS+0xc): undefined reference to `SDL_RWFromFile'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: music.c:(.text.Mix_LoadMUS+0x160): undefined reference to `SDL_FreeRW'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: C:/devkitPro/portlibs/3ds/lib\libSDL_mixer.a(wavestream.o): in function `WAVStream_LoadSong_RW':
wavestream.c:(.text.WAVStream_LoadSong_RW+0x6c): undefined reference to `SDL_ReadLE32'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: wavestream.c:(.text.WAVStream_LoadSong_RW+0x78): undefined reference to `SDL_ReadBE32'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: wavestream.c:(.text.WAVStream_LoadSong_RW+0x80): undefined reference to `SDL_ReadLE32'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: wavestream.c:(.text.WAVStream_LoadSong_RW+0xd8): undefined reference to `SDL_ReadBE16'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: wavestream.c:(.text.WAVStream_LoadSong_RW+0xe4): undefined reference to `SDL_ReadBE32'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: wavestream.c:(.text.WAVStream_LoadSong_RW+0xf0): undefined reference to `SDL_ReadBE16'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: wavestream.c:(.text.WAVStream_LoadSong_RW+0x194): undefined reference to `SDL_ReadLE32'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: wavestream.c:(.text.WAVStream_LoadSong_RW+0x1a0): undefined reference to `SDL_ReadBE32'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: wavestream.c:(.text.WAVStream_LoadSong_RW+0x1d8): undefined reference to `SDL_ReadBE32'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: wavestream.c:(.text.WAVStream_LoadSong_RW+0x1e4): undefined reference to `SDL_ReadBE32'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: wavestream.c:(.text.WAVStream_LoadSong_RW+0x264): undefined reference to `SDL_ReadLE32'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: wavestream.c:(.text.WAVStream_LoadSong_RW+0x270): undefined reference to `SDL_ReadLE32'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: wavestream.c:(.text.WAVStream_LoadSong_RW+0x278): undefined reference to `SDL_ReadLE32'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: wavestream.c:(.text.WAVStream_LoadSong_RW+0x2ac): undefined reference to `SDL_ReadLE32'
c:/devkitpro/devkitarm/bin/../lib/gcc/arm-none-eabi/9.1.0/../../../../arm-none-eabi/bin/ld.exe: wavestream.c:(.text.WAVStream_LoadSong_RW+0x2b8): undefined reference to `SDL_ReadLE32'


Re: SDL: Linker Errors when using SDL_mixer

Posted: Tue Apr 14, 2020 11:21 am
by WinterMute
Couple of things.

1. Don't start trying to shoehorn an autotools based project into a template Makefile. The configury tests and adjusts many things for a given platform which you won't be able to replicate manually and you'll end up with a combination of setting defines manually and "fixing" code that doesn't need fixing because you've confused the build system.

See the work I did on the Switch "port" of chocolate doom for reference. Specifically https://github.com/WinterMute/chocolate ... 989141782b

Please don't continue to attempt to build this with a Makefile based on the template however much anyone tells you otherwise. It's just wrong and will ultimately lead to not being able to upstream your port.


2. Chocolate Doom uses SDL2 and currently we only have a 1.2 port so the way to approach this is to first port SDL2 to 3DS.

Re: SDL: Linker Errors when using SDL_mixer

Posted: Tue Apr 14, 2020 4:27 pm
by JT21
Ah, I see. I've never worked with autotools before, only cmake/makefiles. I'll reconfigure my build with your advice. As for the SDL issue, I plan on backporting the SDL2 code to SDL1.2, which I've already gotten a decent chunk through (as far as I can tell without a proper build to test). So I assume the autotools is similar to the library page with the custom "./configure" command that points to DKA? Thanks for the quick response.