xyproto / zsnes

A maintained fork of ZSNES, a Super Nintendo emulator. The original project needs patches to build and is not maintained anymore: https://sourceforge.net/projects/zsnes/
https://zsnes.com
GNU General Public License v2.0
131 stars 16 forks source link

Cannot build on Ubuntu 20 with instructions on repository. #19

Open TrashRaccoonSnuffy opened 1 year ago

TrashRaccoonSnuffy commented 1 year ago

I am running a 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz (lscpu says it's x86_64), and running make seems to give the following results: /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libz.so when searching for -lz /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libz.a when searching for -lz /usr/bin/ld: cannot find -lz: No such file or directory /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libz.so when searching for -lz /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libX11.so when searching for -lX11 /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libX11.a when searching for -lX11 /usr/bin/ld: cannot find -lX11: No such file or directory /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libX11.so when searching for -lX11 /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libSDL.so when searching for -lSDL /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libSDL.a when searching for -lSDL /usr/bin/ld: cannot find -lSDL: No such file or directory /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libSDL.so when searching for -lSDL /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libpng16.so when searching for -lpng16 /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libpng16.a when searching for -lpng16 /usr/bin/ld: cannot find -lpng16: No such file or directory /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libpng16.so when searching for -lpng16 /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libz.so when searching for -lz /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libz.a when searching for -lz /usr/bin/ld: cannot find -lz: No such file or directory /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libz.so when searching for -lz /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libGL.so when searching for -lGL /usr/bin/ld: cannot find -lGL: No such file or directory /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libGL.so when searching for -lGL

I saw issue #15 and I thought it might have been related, are the libraries necessary still i386?

I actually managed to get way further in compilation by removing -m32 from the cflags, the ifeq ($(wildcard /usr/lib/i386-linux-gnu/.),) line in the Makefile and changing the flags inside to CFLAGS += -I/usr/include/x86_64-linux-gnu -I /usr/include/X11 CXXFLAGS += -I/usr/include/x86_64-linux-gnu -I /usr/include/X11 LDFLAGS = -Wl,--as-needed -no-pie -Wl,--gc-sections -lz -lSDL-1.2 -lpng16 -lX11

and now the errors are only /usr/bin/ld: cannot find -lSDL-1.2: No such file or directory /usr/bin/ld: skipping incompatible /usr/lib32/libm.so when searching for -lm /usr/bin/ld: skipping incompatible /usr/lib32/libm.a when searching for -lm /usr/bin/ld: skipping incompatible /usr/lib32/libm.so when searching for -lm /usr/bin/ld: skipping incompatible /usr/lib32/libm.a when searching for -lm

The libm issue seems pretty easy to fix, but I'm not sure about lsdl2 or if removing -m32 is safe at all.

xyproto commented 1 year ago

Thanks for reporting.

Did you try these instructions?

https://github.com/xyproto/zsnes#debian-and-ubuntu

TrashRaccoonSnuffy commented 1 year ago

These are the exact instructions I tried. It appears to be the same issue as #15 , where the i386 libraries cannot be found and it's trying to look in x86-64 for them. I could probably try this in a 32-bit machine instead and see how that goes, but I'm experimenting to see if I can get it to compile either way.

Update: libsdl1.2-compat-dev:i386 appears to be the only missing package, and that can't be installed directly via sudo apt install libsdl1.2-compat-dev:i386 - will have to look into that.

TrashRaccoonSnuffy commented 1 year ago

I've found a way to get it to fully compile without errors on my current fork but it requires a pretty hacky method of manually downloading the dependencies and turning off a few things in the makefile. https://github.com/TrashRaccoonSnuffy/zsnes/commit/774afa286483d4cba56118cf0404a4cfa0f0c55b

Running the program leads to this though: *** buffer overflow detected ***: terminated

So I'm probably missing something else now, or running the incorrect tools.

xyproto commented 1 year ago

Thanks for adding more information!

Some problems may (possibly, maybe) be with SDL1, but be solved by using sdl2-compat.

Also, the early parts of the Makefile seems to require a 64-bit enviroment, while the rest seems to require a 32-bit environment, which is odd and on my TODO list in the back of my head for things I want to fix. This seems to be a Debian/Ubuntu specific issue, though.

I will give it a go on Ubuntu 20 as well.

TrashRaccoonSnuffy commented 1 year ago

This crash occurs in clearvidsound() in initc.c , specifically at

memset(&echoon0, 0, PHdspsave2);

Possibly related to #5

There is a patch here https://github.com/rpmfusion/zsnes/blob/master/zsnes-1.51-FORTIFY_SOURCE.patch that I will try and I will report back if it does anything.

Program received signal SIGABRT, Aborted.
0xf7fc4579 in __kernel_vsyscall ()
(gdb) bt 10
#0  0xf7fc4579 in __kernel_vsyscall ()
#1  0xf7a88a37 in ?? () from /lib/i386-linux-gnu/libc.so.6
#2  0xf7a37685 in raise () from /lib/i386-linux-gnu/libc.so.6
#3  0xf7a203ac in abort () from /lib/i386-linux-gnu/libc.so.6
#4  0xf7a7b3bc in ?? () from /lib/i386-linux-gnu/libc.so.6
#5  0xf7b3397c in __fortify_fail () from /lib/i386-linux-gnu/libc.so.6
#6  0xf7b321af in __chk_fail () from /lib/i386-linux-gnu/libc.so.6
#7  0x082c15d1 in memset (__len=<optimized out>, __ch=0, __dest=<optimized out>) at /usr/include/bits/string_fortified.h:59
#8  clearvidsound () at initc.c:1376
#9  0x082c379a in init65816 () at initc.c:2485
(More stack frames follow...)
TrashRaccoonSnuffy commented 1 year ago

image Confirmed working after https://github.com/TrashRaccoonSnuffy/zsnes/commit/f77ec1a096d22ebeb1a2f7b2c8389c890f7a97c6

Games do not boot at all and lead to a buffer overflow error however. More patches will have to be applied to get it fully working. There also needs to be an easier way to set up the packages for i386, since atleast on ubuntu attempting to install libc i386 wants to delete the x86_64 version and that can't be worked with.

Update: Turning off _FORTIY_SOURCE seems to fix the issues, but that probably isn't the safest thing to do.

xyproto commented 1 year ago

Thanks for the additional info and for your contributions.

I'll test and patch this when I can. (It's been a busy week). 🙂

TrashRaccoonSnuffy commented 1 year ago

Thanks. I've decided to make a separate branch to put all the changes necessary to compile on Ubuntu. It's already working with https://github.com/xyproto/zsnes/commit/5265da3cca115cc30438a57e8c307757b66bb5d8 and the other step I described above with manually downloading the i386 packages and putting their usr folder in the root.

I already put a fix on the main repository for one of the buffer overflow issues, but on Ubuntu it's necessary to disable FORTIFY_SOURCE to get it to fully work otherwise the emulator will crash when loading a new game after one is already loaded. This is probably due to a GCC bug.