Homebrew Question Linker errors while porting sld2 project (beginner)

Jons

New Member
OP
Newbie
Joined
Apr 17, 2021
Messages
3
Trophies
0
Age
29
XP
49
Country
Aruba
Hello there, im trying to teach myself porting applications to nintendo switch. The project i've chosen to port is OpenDune. I'm having some problems which I no doubt stem from my inexperience with porting in general. I'm using devkitproA64 with libnx and the (from what understand) the necessary portlibs.

The code is compiling but I'm getting the following linker error:

Code:
/opt/devkitpro/devkitA64/bin/../lib/gcc/aarch64-none-elf/10.2.0/../../../../aarch64-none-elf/bin/ld: timer.o: in function `SleepAndProcessBackgroundTasks':
timer.c:(.text.SleepAndProcessBackgroundTasks+0x18): undefined reference to `pause'
/opt/devkitpro/devkitA64/bin/../lib/gcc/aarch64-none-elf/10.2.0/../../../../aarch64-none-elf/bin/ld: timer.o: in function `Timer_Init':
timer.c:(.text.Timer_Init+0x30): undefined reference to `sigaction'
/opt/devkitpro/devkitA64/bin/../lib/gcc/aarch64-none-elf/10.2.0/../../../../aarch64-none-elf/bin/ld: timer.c:(.text.Timer_Init+0x4c): undefined reference to `setitimer'
/opt/devkitpro/devkitA64/bin/../lib/gcc/aarch64-none-elf/10.2.0/../../../../aarch64-none-elf/bin/ld: timer.o: in function `Timer_Uninit':
timer.c:(.text.Timer_Uninit+0x1c): undefined reference to `setitimer'

I'm using the following flags while building the app
Code:
CFLAGS         = -O2 -pthread -fomit-frame-pointer -Wno-variadic-macros -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec -O2 -ffunction-sections -fdata-sections -fno-common -Wall -Wsign-compare -Wundef -Wwrite-strings -Wpointer-arith -W -Wredundant-decls -Wformat=2 -Wformat-security -Wno-format-nonliteral -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-but-set-parameter -Winit-self -fno-strict-aliasing -Wcast-qual -fno-strict-overflow -Wno-free-nonheap-object  -DUNIX -I/home/jons/projects/OpenDUNE/include -D_FORTIFY_SOURCE=2 -DWITH_SDL2 -I/opt/devkitpro/portlibs/switch/include/SDL2 -D__SWITCH__ $(INCLUDE) `sdl2-config --cflags` -march=armv8-a -mtune=cortex-a57 -mtp=soft -ftls-model=local-exec -isystem /opt/devkitpro/libnx/include -I/opt/devkitpro/portlibs/switch/include -DSDL_FORCE_INLINE='static __inline' -DWITHOUT_SDLIMAGE -DNDEBUG
CFLAGS_BUILD   =  -pthread -fno-common -Wall -Wsign-compare -Wundef -Wwrite-strings -Wpointer-arith -W -Wredundant-decls -Wformat=2 -Wformat-security -Wno-format-nonliteral -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-but-set-parameter -Winit-self -fno-strict-aliasing -Wcast-qual -fno-strict-overflow -Wno-free-nonheap-object  -D_FORTIFY_SOURCE=2 -O1 -DNDEBUG
ASFLAGS        =
LIBS           =  -L/opt/devkitpro/portlibs/switch/lib `sdl2-config --libs` -lSDL2 -march=armv8-a -fPIE -L/opt/devkitpro/libnx/lib -lstdc++ -lm -lEGL  -lGLESv2 -lglapi -ldrm_nouveau  -lnx
LDFLAGS        = -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec -L/opt/devkitpro/portlibs/switch/lib -L/opt/devkitpro/libnx/lib -specs=$(DEVKITPRO)/libnx/switch.specs -static

My guess is that i should be linking against some library, or that the toolchain or system does not support these undefined methods.
I have been googling what library i need to link against to get these undefined implementations to no success. There is probably some very basic knowledge I'm missing. I would be very grateful if someone could point me in the right direction or point me to a resource that can broaden my basic understanding.
 

chaoskagami

G̷̘̫̍̈́̊̓̈l̴̙͔̞͠i̵̳͊ţ̸̙͇͒̓c̵̬̪̯̥̳͒͌̚h̵̹̭͛̒̊̽̚
Developer
Joined
Mar 26, 2016
Messages
1,365
Trophies
1
Location
↑↑↓↓←→←→BA
Website
github.com
XP
2,287
Country
United States
My guess is that i should be linking against some library, or that the toolchain or system does not support these undefined methods.

The Switch does not support POSIX signals. You have to patch the code.
 
Last edited by chaoskagami,

Jons

New Member
OP
Newbie
Joined
Apr 17, 2021
Messages
3
Trophies
0
Age
29
XP
49
Country
Aruba
Alright, thanks for the clear answer. Is there a reason why this wasn't caught in the compilation process? Am I somehow using headers from my system instead of the devkita64 headers?
 

chaoskagami

G̷̘̫̍̈́̊̓̈l̴̙͔̞͠i̵̳͊ţ̸̙͇͒̓c̵̬̪̯̥̳͒͌̚h̵̹̭͛̒̊̽̚
Developer
Joined
Mar 26, 2016
Messages
1,365
Trophies
1
Location
↑↑↓↓←→←→BA
Website
github.com
XP
2,287
Country
United States
As far as I can tell, newlib provides declarations in sys/time.h but no implementation. This is pretty typical for most homebrew toolchains; they don't generally roll their own libc and use newlib as a base.

One obviously wrong thing I can see aside from that is the way sdl2-config is used. `sdl2-config --cflags` is wrong without additionally passing `--prefix=$DEVKITPRO/portlibs/switch`. In practice, since that's provided last in CFLAGS that probably means you're including your system SDL2 headers. I doubt that affects much of anything since SDL2 doesn't munge its headers in any way when installing, though.
 
Last edited by chaoskagami,

Jons

New Member
OP
Newbie
Joined
Apr 17, 2021
Messages
3
Trophies
0
Age
29
XP
49
Country
Aruba
Alright that makes sense.

Thanks for the insight. Things like that helps a lot. Much of the resources I looked at assume i have a basic understanding of how these toolchains work and are to be used.

I think the sdl2-config --prefix flag isn't needed in my environment because i'm sourcing the $DEVKITPRO/switchvars.sh file and i don't have a sdl2 installation on my system (it uses the sdl-config bin inside the devkitpro directory). The output of sdl2-config --cflags give me the include dirs in the portlibs directory. I will add the flag either way.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Xdqwerty @ Xdqwerty: i think im a bad person