pspdev / psplibraries

A script to automatically build open-source libraries for PSP homebrew development.
47 stars 45 forks source link

Add SDL2 auxiliary libraries #62

Closed carstene1ns closed 4 years ago

carstene1ns commented 4 years ago
sharkwouter commented 4 years ago

I'm currently using this in the hopes of being able to port panel-pop to PSP. I'm having issues with linking, though. I think ${PSPLIBRARIES} in the cmake toolchain file may need to be updated. There has to be a better way than trial and error to get linking right, though.

Anyway, here is the relevant part of my build script:

include_directories(${PSPDEV}/psp/include/SDL2
        ${PSPDEV}/psp/include/jsoncpp
        ${PSPDEV}/psp/include
        )

target_link_libraries(panel-pop PRIVATE
        SDL2main
        SDL2
        SDL2_ttf
        SDL2_mixer
        jsoncpp
        ${PSP_LIBRARIES}
        freetype
        zzip
        modplug
        )

And this is what I'm running into:

outer@wouter-pc:~/Sources/panel-pop/psp$ make
[  1%] Linking CXX executable panel-pop
CMakeFiles/panel-pop.dir/SDLContext.cpp.obj: In function `SDLContext::init()':
(.text+0x29c): undefined reference to `IMG_Init'
CMakeFiles/panel-pop.dir/SDLContext.cpp.obj: In function `SDLContext::makeTextureFromImage(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
(.text+0x728): undefined reference to `IMG_Load'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_OpenFontIndexRW':
(.text+0x1440): undefined reference to `FT_Select_Size'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libSDL2_mixer.a(mixer.o): In function `Mix_LoadWAV_RW':
(.text+0x654): undefined reference to `SDL_LoadWAV_RW'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libSDL2_mixer.a(music_ogg.o): In function `OGG_Load':
music_ogg.c:(.text+0x10): undefined reference to `ov_clear'
music_ogg.c:(.text+0x18): undefined reference to `ov_clear'
music_ogg.c:(.text+0x20): undefined reference to `ov_info'
music_ogg.c:(.text+0x24): undefined reference to `ov_info'
music_ogg.c:(.text+0x2c): undefined reference to `ov_comment'
music_ogg.c:(.text+0x30): undefined reference to `ov_comment'
music_ogg.c:(.text+0x38): undefined reference to `ov_open_callbacks'
music_ogg.c:(.text+0x3c): undefined reference to `ov_open_callbacks'
music_ogg.c:(.text+0x44): undefined reference to `ov_pcm_total'
music_ogg.c:(.text+0x48): undefined reference to `ov_pcm_total'
music_ogg.c:(.text+0x50): undefined reference to `ov_read'
music_ogg.c:(.text+0x54): undefined reference to `ov_read'
music_ogg.c:(.text+0x5c): undefined reference to `ov_time_seek'
music_ogg.c:(.text+0x60): undefined reference to `ov_time_seek'
music_ogg.c:(.text+0x68): undefined reference to `ov_pcm_seek'
music_ogg.c:(.text+0x6c): undefined reference to `ov_pcm_seek'
music_ogg.c:(.text+0x74): undefined reference to `ov_pcm_tell'
music_ogg.c:(.text+0x78): undefined reference to `ov_pcm_tell'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `getsockopt':
(.text+0x40): undefined reference to `sceNetInetGetsockopt'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `getsockopt':
(.text+0x84): undefined reference to `sceNetInetGetErrno'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `setsockopt':
(.text+0xe8): undefined reference to `sceNetInetSetsockopt'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `setsockopt':
(.text+0x178): undefined reference to `sceNetInetGetErrno'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/panel-pop.dir/build.make:819: panel-pop] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/panel-pop.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

I've tried linking to ogg, vorbis and vorbisfile, but that seems to make it worse. It's this repo and branch: https://github.com/sharkwouter/panel-pop/tree/psp-port

carstene1ns commented 4 years ago

I've tried linking to ogg, vorbis and vorbisfile, but that seems to make it worse.

log?

sharkwouter commented 4 years ago

Okay, I managed to trim it down to this:

wouter@wouter-pc:~/Sources/panel-pop/psp$ make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wouter/Sources/panel-pop/psp
[  1%] Linking CXX executable panel-pop
CMakeFiles/panel-pop.dir/SDLContext.cpp.obj: In function `SDLContext::init()':
(.text+0x29c): undefined reference to `IMG_Init'
CMakeFiles/panel-pop.dir/SDLContext.cpp.obj: In function `SDLContext::makeTextureFromImage(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
(.text+0x728): undefined reference to `IMG_Load'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_OpenFontIndexRW':
(.text+0x1440): undefined reference to `FT_Select_Size'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libSDL2_mixer.a(mixer.o): In function `Mix_LoadWAV_RW':
(.text+0x654): undefined reference to `SDL_LoadWAV_RW'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `getsockopt':
(.text+0x40): undefined reference to `sceNetInetGetsockopt'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `getsockopt':
(.text+0x84): undefined reference to `sceNetInetGetErrno'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `setsockopt':
(.text+0xe8): undefined reference to `sceNetInetSetsockopt'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `setsockopt':
(.text+0x178): undefined reference to `sceNetInetGetErrno'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/panel-pop.dir/build.make:819: panel-pop] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/panel-pop.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

With the following cmake:

include_directories(${PSPDEV}/psp/include/SDL2
        ${PSPDEV}/psp/include/jsoncpp
        ${PSPDEV}/psp/sdk/include
        ${PSPDEV}/psp/include
        )

target_link_libraries(panel-pop PRIVATE
        SDL2main
        SDL2
        SDL2_ttf
        SDL2_mixer
        jsoncpp
        ${PSP_LIBRARIES}
        freetype
        vorbisfile
        vorbis
        ogg
        modplug
        )

Modplug is needed because I had libmodplug installed while SDL2 was being installed.

So, to summarize:

Could these be added to the .pc files in ${PSPDEV}/psp/lib/pkgconfig which these libraries add?

sharkwouter commented 4 years ago

I'm not sure why the issues with the pspnet related libraries are happening. Libraries should be loaded from ${PSPDEV}/psp/sdk/lib because of the toolchain file and pspnet and pspnet_inet are added by psplibraries. The functions it asks for are actually there. That being said, I don't think these libraries are needed for this application at all.

sharkwouter commented 4 years ago

I can decrease ${PSP_LIBRARIES} from this:

set(PSP_LIBRARIES
        "-lg -lc -lpspdebug -lpspctrl -lpspsdk \
        -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpspaudiolib \
        -lpsputility -lGL \
        -lpspvfpu -lpspdisplay -lpsphprm -lpspirkeyb \
        -lpsprtc -lpspaudio -lpspvram  -lpspgu -lpspge -lpspuser \
        -L${PSPSDK}/lib -L${PSPDEV}/lib"
)

To this:

set(PSP_LIBRARIES
        "-lg -lc -lpspdebug -lpspctrl \
         -lGL \
        -lpspvfpu -lpspdisplay -lpsphprm \
        -lpsprtc -lpspaudio -lpspvram  -lpspgu -lpspge -lpspuser \
        -L${PSPSDK}/lib -L${PSPDEV}/lib"
)

Without it changing anything to the linking errors with this application.

carstene1ns commented 4 years ago

The build systems of SDL2_image, mixer and such are unfortunately broken for static linking. You are not telling me anything new. :grinning: https://github.com/devkitPro/pacman-packages/commit/c8a3b96a033a4d0651fdf91501664b8c82d00316#diff-8598ea3da434822ca3d02dff6dda3c60R49-R50 https://github.com/devkitPro/pacman-packages/commit/a441298365f8b9efff4870c089be620ee70eb4fd#diff-072a2d3691152de1bcd983f2cb9cb06fR45-R46 https://github.com/devkitPro/pacman-packages/commit/875ad00009ecb92065cd54a0619f113524c4dcb4#diff-6873202dc678ac4497a09fb89fa40b29R45-R46 https://github.com/devkitPro/pacman-packages/commit/507089093949e394de7da8f62fba5c7d52015356#diff-344cc78cb8bd32866f58448e7c214521R44-R45

sharkwouter commented 4 years ago

Oh damn, I completely missed that. I'll do some testing and report back D:

sharkwouter commented 4 years ago

Okay, I've added SDL2_image, png, jpeg and z this time. Now I'm left with these:

wouter@wouter-pc:~/Sources/panel-pop/psp$ make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wouter/Sources/panel-pop/psp
[  1%] Linking CXX executable panel-pop
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_OpenFontIndexRW':
(.text+0x1440): undefined reference to `FT_Select_Size'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libSDL2_mixer.a(mixer.o): In function `Mix_LoadWAV_RW':
(.text+0x654): undefined reference to `SDL_LoadWAV_RW'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `getsockopt':
(.text+0x40): undefined reference to `sceNetInetGetsockopt'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `getsockopt':
(.text+0x84): undefined reference to `sceNetInetGetErrno'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `setsockopt':
(.text+0xe8): undefined reference to `sceNetInetSetsockopt'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `setsockopt':
(.text+0x178): undefined reference to `sceNetInetGetErrno'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/panel-pop.dir/build.make:819: panel-pop] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/panel-pop.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

The SDL2_mixer and SDL2_ttf errors might be bugs with this PR. I have no idea what's up with the pspnet issues :(

sharkwouter commented 4 years ago

Yep, this part is my fault:

/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `getsockopt':
(.text+0x40): undefined reference to `sceNetInetGetsockopt'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `getsockopt':
(.text+0x84): undefined reference to `sceNetInetGetErrno'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `setsockopt':
(.text+0xe8): undefined reference to `sceNetInetSetsockopt'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libc.a(setsockopt.o): In function `setsockopt':
(.text+0x178): undefined reference to `sceNetInetGetErrno'
collect2: error: ld returned 1 exit status

You can ignore that. Which just leaves:

/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_OpenFontIndexRW':
(.text+0x1440): undefined reference to `FT_Select_Size'
/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libSDL2_mixer.a(mixer.o): In function `Mix_LoadWAV_RW':
(.text+0x654): undefined reference to `SDL_LoadWAV_RW'
carstene1ns commented 4 years ago

Did you reorder the libs accordingly? Freetype might be actually because the lib is old, but the sdl wave looks like ordering to me

sharkwouter commented 4 years ago

Oh, I read over one of your suggestions. Loading SDL2_mixer before SDL2 resolves one of the issues.

sharkwouter commented 4 years ago

This one remains for now:

/usr/local/pspdev/lib/gcc/psp/9.3.0/../../../../psp/lib/libSDL2_ttf.a(SDL_ttf.o): In function `TTF_OpenFontIndexRW':
(.text+0x1440): undefined reference to `FT_Select_Size'
carstene1ns commented 4 years ago

Is as i figured, our freetype is too old :grin: It is available since 2.2, but we ship ancient 2.1.10. Time to update.

sharkwouter commented 4 years ago

I've been able to build panel-pop with this now. I worked out all the linking issues. It doesn't work yet, but it's a start.

carstene1ns commented 4 years ago

Besides the freetype update, all of this should be either backward compatible or new, so it should not do much harm to merge this now. I have also done some tests and worked around some corner cases.

sharkwouter commented 4 years ago

An issue with this change has been found. It does not provide sdl-config, sdl2-config or freetype-config (the last one I'm not 100% sure about), but it does seem to require them. The problem with this is that the pspdev docker container needs to be significantly larger, the difference is like 500 mb, for all libraries to build successfully.

carstene1ns commented 4 years ago

sdl-config and freetype-config work like before. Also, sdl2-config gets not installed by your script (and dependencies are also missing). 😉

The size change should be investigated, yes.

carstene1ns commented 4 years ago

Forgot to rm -r build folder maybe?

sharkwouter commented 4 years ago

The changes to scripts/SDL_ttf.sh and scripts/SDL_gfx.sh introduced a dependency upon sdl-config, because they use -with-sdl-prefix now. I think we should see this as a bug. I think your are right about sdl2-config, though, we should include that.

I need to investigate the issues related to freetype further. It was reported in discord that opentri no longer builds in docker. I will try to reproduce this tonight and report back.

Edit: I was wrong, there is a different reason we need sdl-config for SDL-ttf and SDL-gfx now. I think we should try to avoid this, though. In the future some distributions might not ship sdl-config anymore, since SDL1 as already unsupported.

sharkwouter commented 4 years ago

Sorry for being so vague, I'm going off of a report on Discord about building pspdev-docker. I'll test it myself tonight and write a proper issue about what's failing.

carstene1ns commented 4 years ago

No problem, most of the problems happen on macOS as well, so I need to fix them anyway.