switchbrew / libnx

Library for Switch Homebrew
https://switchbrew.github.io/libnx/
ISC License
1.26k stars 167 forks source link

default_window: fix missing weak declarations #609

Closed liamwhite closed 1 year ago

liamwhite commented 1 year ago

These were clearly intended to be overridable, but weren't since they weren't declared weak at the definition.

libnx.a(default_window.o): in function `__nx_win_init':
default_window.c:(.text.__nx_win_init+0x0): multiple definition of `__nx_win_init'
main.o:main.cpp:(.text.__nx_win_init+0x0): first defined here

https://github.com/switchbrew/libnx/blob/dca4fb772aabf24c680561337f6bdffa69d7eb9a/nx/source/runtime/init.c#L101 https://github.com/switchbrew/libnx/blob/dca4fb772aabf24c680561337f6bdffa69d7eb9a/nx/source/runtime/init.c#L152

fincs commented 1 year ago

__nx_win_init/__nx_win_exit are declared as weak in init.c/fini.c so that the linker does not pull them if you don't ever use the default window. It is intentional that they are defined as strong symbols in default_window.c.

The default window mechanism is intended to reduce boilerplate for 99% of use cases, and using it is not a requirement in any of the homebrew APIs that exist. If you need to obtain a NWindow in a specific way, then you can do that directly with VI APIs instead of bothering with the default window.