SDL 2.28.5 linker error: unrecognized command-line option '-march'

Post Reply
staphen
Posts: 9
Joined: Tue Jun 29, 2021 3:48 am

SDL 2.28.5 linker error: unrecognized command-line option '-march'

Post by staphen » Sat Feb 03, 2024 12:08 am

Using the following example code with dkp-libs switch-sdl2 2.28.5-1 installed, I get the following error from the linker.

CMakeLists.txt

Code: Select all

cmake_minimum_required(VERSION 3.28)
project(test)
find_package(SDL2 REQUIRED)
add_executable(test main.cpp)
target_link_libraries(test SDL2::SDL2-static)
main.cpp

Code: Select all

int main() { return 0; }
Error:

Code: Select all

$ /opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake .
...
-- Configuring done (1.9s)
-- Generating done (0.0s)
-- Build files have been written to: ...
$ make
[ 50%] Building CXX object CMakeFiles/test.dir/main.o
[100%] Linking CXX executable test.elf
aarch64-none-elf-g++: error: unrecognized command-line option '-march'; did you mean '-march='?
make[2]: *** [CMakeFiles/test.dir/build.make:98: test.elf] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/test.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
It seems to me that this is due to the introduction of the -march=armv8-a flag to EXTRA_LDFLAGS in the configure script for the SDL fork.
https://github.com/devkitPro/SDL/blob/s ... ure#L27532

It causes the problem because SDL assigns the value of that variable to SDL_STATIC_LIBS directly, then uses some regex matching in sdl2-config.cmake.in to extract the -mwindows flag (among others) and potentially include it in the list of libraries in INTERFACE_LINK_LIBRARIES. Linking to SDL2::SDL2-static will therefore trigger the error.

You can use these links to follow the trail.
https://github.com/devkitPro/SDL/blob/s ... ure#L27840
https://github.com/devkitPro/SDL/blob/s ... ake.in#L44
https://github.com/devkitPro/SDL/blob/s ... ake.in#L56
https://github.com/devkitPro/SDL/blob/s ... in#L63-L66 (kind of irrelevant, but this demonstrates parsing of the -mwindows flag)
https://github.com/devkitPro/SDL/blob/s ... ke.in#L166

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

Re: SDL 2.28.5 linker error: unrecognized command-line option '-march'

Post by WinterMute » Sun Feb 04, 2024 5:08 am

https://github.com/devkitPro/SDL/blob/s ... ake.in#L56 is the culprit and also turned -lstdc++ into -lstdc when I removed the march bit. I'm not sure this is actually what we want yet but it does get a project building. I've packaged a new version of switch-sdl2 with this fix.

You don't need to use SDL2::SDL2-static explictly, you can use target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES}) instead and cmake will do the right thing. That way you get dynamic libsdl on platforms where that's supported.

I have CMakeLists.txt like this

Code: Select all

cmake_minimum_required(VERSION 3.28)
project(test)

set(CMAKE_CXX_STANDARD 14)

find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})

if(NINTENDO_SWITCH)
  nx_generate_nacp (${PROJECT_NAME}.nacp
    NAME    "${PROJECT_NAME}"
    AUTHOR  "<author>"
  )

  nx_create_nro(${PROJECT_NAME}
    NACP  ${PROJECT_NAME}.nacp
  )
endif()
Help keep devkitPro toolchains free, Donate today

Personal Blog

staphen
Posts: 9
Joined: Tue Jun 29, 2021 3:48 am

Re: SDL 2.28.5 linker error: unrecognized command-line option '-march'

Post by staphen » Sun Feb 04, 2024 7:00 pm

I've confirmed the latest package resolves the issue with the sample as well as with DevilutionX. Now I guess we'll just need to wait for the docker image to be updated. Thanks!

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

Re: SDL 2.28.5 linker error: unrecognized command-line option '-march'

Post by WinterMute » Wed Feb 07, 2024 12:38 pm

staphen wrote: Sun Feb 04, 2024 7:00 pm I've confirmed the latest package resolves the issue with the sample as well as with DevilutionX. Now I guess we'll just need to wait for the docker image to be updated. Thanks!
docker has been updated now. I take the updated SDL is behaving fine for you otherwise?
Help keep devkitPro toolchains free, Donate today

Personal Blog

staphen
Posts: 9
Joined: Tue Jun 29, 2021 3:48 am

Re: SDL 2.28.5 linker error: unrecognized command-line option '-march'

Post by staphen » Wed Feb 07, 2024 4:37 pm

WinterMute wrote: Wed Feb 07, 2024 12:38 pm docker has been updated now. I take the updated SDL is behaving fine for you otherwise?
Thanks, we just merged the PR to use the latest Docker image, and the build appears to be working fine. As for how SDL is behaving, I tried running the game in Ryujinx just now, but it seems I can't get past the main menu because my Pro Controller inputs aren't working. I tested with an older build and verified that everything works fine so it doesn't seem to be an issue with how I have Ryujinx configured. So there seems to be some issue in SDL related to controller input.

But audio and video both appear to be working just fine.

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

Re: SDL 2.28.5 linker error: unrecognized command-line option '-march'

Post by WinterMute » Wed Feb 07, 2024 10:47 pm

Does it work with joycons or is it a general controller issue. I tested with what I had handy but I didn't think to dig out a pro-controller. I had an attempt at building devilution but I failed at the first hurdle unfortunately - this is the last few lines of my attempt to configure a build

Code: Select all

-- Could NOT find Gettext (missing: GETTEXT_MSGMERGE_EXECUTABLE GETTEXT_MSGFMT_EXECUTABLE) 
CMake Error at /opt/devkitpro/cmake/Platform/NintendoSwitch.cmake:135 (message):
  nx_create_nro: cannot find romfs dir:
  /Users/davem/projects/switch/devilutionX/_switch/assets
Call Stack (most recent call first):
  CMakeLists.txt:424 (nx_create_nro)


-- Configuring incomplete, errors occurred!
Do I need to do something special here? I know I've built this before when testing but it's been a long time.
Help keep devkitPro toolchains free, Donate today

Personal Blog

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

Re: SDL 2.28.5 linker error: unrecognized command-line option '-march'

Post by WinterMute » Thu Feb 08, 2024 1:22 am

I also tried setting DDEVILUTIONX_ASSETS_OUTPUT_DIRECTORY but ended up with

Code: Select all

davem@straylight devilutionX % cmake --build _switch --parallel
[0/2] Re-checking globbed directories...
ninja: error: dependency cycle: /Users/davem/projects/switch/devilutionX/assets/arena/church.dun -> /Users/davem/projects/switch/devilutionX/assets/arena/church.dun
Help keep devkitPro toolchains free, Donate today

Personal Blog

staphen
Posts: 9
Joined: Tue Jun 29, 2021 3:48 am

Re: SDL 2.28.5 linker error: unrecognized command-line option '-march'

Post by staphen » Thu Feb 08, 2024 3:16 am

WinterMute wrote: Wed Feb 07, 2024 10:47 pm Does it work with joycons or is it a general controller issue. I tested with what I had handy but I didn't think to dig out a pro-controller. I had an attempt at building devilution but I failed at the first hurdle unfortunately - this is the last few lines of my attempt to configure a build

Code: Select all

-- Could NOT find Gettext (missing: GETTEXT_MSGMERGE_EXECUTABLE GETTEXT_MSGFMT_EXECUTABLE) 
CMake Error at /opt/devkitpro/cmake/Platform/NintendoSwitch.cmake:135 (message):
  nx_create_nro: cannot find romfs dir:
  /Users/davem/projects/switch/devilutionX/_switch/assets
Call Stack (most recent call first):
  CMakeLists.txt:424 (nx_create_nro)


-- Configuring incomplete, errors occurred!
Do I need to do something special here? I know I've built this before when testing but it's been a long time.
I tried switching my input profile over to Joycons just now, but it has the same issue.

As for that error, it looks like CMake creates the folder during the configure step when gettext is found.
https://github.com/diasurgical/deviluti ... ke#L11-L12

If you don't want to have to install gettext, maybe you can just "mkdir -p _switch/assets" before running cmake.

rsn8887
Posts: 1
Joined: Thu Feb 08, 2024 7:03 am

Re: SDL 2.28.5 linker error: unrecognized command-line option '-march'

Post by rsn8887 » Thu Feb 08, 2024 7:09 am

WinterMute wrote: Wed Feb 07, 2024 10:47 pm Does it work with joycons or is it a general controller issue. I tested with what I had handy but I didn't think to dig out a pro-controller. (...)
It didn't work with any controller. The whole GameController interface of SDL2 was borked. The joystick interface worked. Here's the fix:

https://github.com/devkitPro/SDL/pull/54

The GUID construction changed at some point in SDL2, and is now done via a function instead of copying the name string directly. This can also be seen in other upstreamed platform code, such as Vita and PS2. It would be cool to upstream the Switch port of SDL2, just as was done for Vita, if possible.

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

Re: SDL 2.28.5 linker error: unrecognized command-line option '-march'

Post by WinterMute » Sat Feb 10, 2024 12:56 pm

rsn8887 wrote: Thu Feb 08, 2024 7:09 am
WinterMute wrote: Wed Feb 07, 2024 10:47 pm Does it work with joycons or is it a general controller issue. I tested with what I had handy but I didn't think to dig out a pro-controller. (...)
It didn't work with any controller. The whole GameController interface of SDL2 was borked. The joystick interface worked. Here's the fix:

https://github.com/devkitPro/SDL/pull/54

The GUID construction changed at some point in SDL2, and is now done via a function instead of copying the name string directly. This can also be seen in other upstreamed platform code, such as Vita and PS2. It would be cool to upstream the Switch port of SDL2, just as was done for Vita, if possible.
Thanks for doing this. I've merged your patch, released -2.28.5-3 and updated the docker image so hopefully this should work now.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest