thomasokken / free42

Free42 : An HP-42S Calculator Simulator
https://thomasokken.com/free42/
GNU General Public License v2.0
280 stars 54 forks source link

Build errors on postmarket OS (Alpine) #70

Closed tomoqv closed 4 months ago

tomoqv commented 4 months ago

Hi, I really like the Free42 calculator and have been using it on various Linux distros, including mobile Linux. I am currently running Postmarket OS with Gnome-mobile on a OnePlus 6 as my main phone and would like to install it there too.

I came this far on the phone: $ apk add libgtk-3-dev (not available on PMOS) $ apk add libasound2-dev (not available on PMOS) $ git clone https://github.com/thomasokken/free42.git $ cd free42/gtk $ make BCD_MATH=1 AUDIO_ALSA=1 Getting the following build errors:

../free42/gtk$ sudo make BCD_MATH=1 AUDIO_ALSA=1
Package gtk+-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-3.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'gtk+-3.0' not found
g++  -MMD -Wall -Wno-parentheses -Wno-write-strings -Wno-sign-compare -Wno-narrowing -Wno-constant-conversion -Wno-sometimes-uninitialized -Wno-format-truncation -Wno-class-memaccess -Wno-unknown-warning-option -g  -DGDK_DISABLE_DEPRECATION_WARNINGS -DGTK_DISABLE_SINGLE_INCLUDES -DGSEAL_ENABLE -DVERSION="\"3.1.8\"" -DVERSION_PLATFORM="\"Linux\"" -DDECIMAL_CALL_BY_REFERENCE=1 -DDECIMAL_GLOBAL_ROUNDING=1 -DDECIMAL_GLOBAL_ROUNDING_ACCESS_FUNCTIONS=1 -DDECIMAL_GLOBAL_EXCEPTION_FLAGS=1 -DDECIMAL_GLOBAL_EXCEPTION_FLAGS_ACCESS_FUNCTIONS=1 -fsigned-char -DBID_SIZE_LONG=8 -fno-exceptions -fno-rtti -D_WCHAR_T_DEFINED -DBCD_MATH -DAUDIO_ALSA -DALSALIB="\"libasound.so.2\"" -c -o shell_main.o shell_main.cc
shell_main.cc:18:10: fatal error: gtk/gtk.h: No such file or directory
   18 | #include <gtk/gtk.h>
      |          ^~~~~~~~~~~
compilation terminated.
make: *** [Makefile:118: shell_main.o] Error 1

I would really like to know how to build this, so any advice or hint is welcome!

Thanks again for this great software!

thomasokken commented 4 months ago

I'm not familiar with PostmarketOS, so I can't tell you how to fix this problem. But the problem itself is clear: the GTK3 development package is missing.

The package installation lines from my Raspbian build instructions,

# apt install libgtk-3-dev # apt install libasound2-dev

are for Debian-based distributions, including Raspbian and Ubuntu. The package names for PostmarketOS may be different.

tomoqv commented 4 months ago

Ok, I came a bit further by installing these two packages:

apk add gtk+3.0-dev
apk add alsa-lib-dev

However, now the build ends with this error:

In file included from src/bid_internal.h:39,
                 from src/bid_strtod.h:35,
                 from src/strtod32.c:30:
src/bid_functions.h:46:15: error: conflicting types for 'wchar_t'; have 'int'
   46 | typedef int   wchar_t;
      |               ^~~~~~~
In file included from /usr/include/stdlib.h:21,
                 from /usr/include/fortify/stdlib.h:23,
                 from src/bid_strtod.h:32:
/usr/include/bits/alltypes.h:15:18: note: previous declaration of 'wchar_t' with type 'wchar_t' {aka 'unsigned int'}
   15 | typedef unsigned wchar_t;
      |                  ^~~~~~~
gmake[1]: *** [makefile:356: strtod32.o] Error 1
gmake[1]: Leaving directory '/home/user/Dokument/Kod/free42/gtk/IntelRDFPMathLib20U1/LIBRARY'
mv: can't rename 'libbid.a': No such file or directory
ln -s IntelRDFPMathLib20U1/TESTS/readtest.c
ln: readtest.c: File exists
make: *** [Makefile:137: gcc111libbid.a] Error 1
thomasokken commented 4 months ago

An error while trying to build the Intel library, apparently wchar_t is predefined and the build does not expect that. Hmm, I don't think I've seen that before.

Try adding -D_WCHAR_T_DEFINED in line 16 of intel-lib-unknown-32bit.patch and/or intel-lib-unknown-64bit.patch (whichever one is relevant to your build, or both). Then do make cleaner and try a new build.

tomoqv commented 4 months ago

Thanks for helping out. Just to be clear, I changed this line (in both files): ! _CFLAGS_CC := -fsigned-char -DBID_SIZE_LONG=8 to _CFLAGS_CC := -fsigned-char -DBID_SIZE_LONG=8 -D_WCHAR_T_DEFINED

Here are the last lines of the most recent build:

patching file LIBRARY/float128/dpml_exception.c
patching file TESTS/readtest.c
patching file LIBRARY/src/bid128_hypot.c
patch: **** context mangled in hunk at line 4
gmake[1]: Entering directory '/home/user/Dokument/Kod/free42/gtk/IntelRDFPMathLib20U1/LIBRARY'
makefile.iml_head:356: *** Unknown host architecture aarch64.  Stop.
gmake[1]: Leaving directory '/home/user/Dokument/Kod/free42/gtk/IntelRDFPMathLib20U1/LIBRARY'
mv: can't rename 'libbid.a': No such file or directory
ln -s IntelRDFPMathLib20U1/TESTS/readtest.c
g++ -o free42dec  shell_main.o shell_skin.o skins.o keymap.o shell_loadimage.o shell_spool.o core_main.o core_commands1.o core_commands2.o core_commands3.o core_commands4.o core_commands5.o core_commands6.o core_commands7.o core_display.o core_globals.o core_helpers.o core_keydown.o core_linalg1.o core_linalg2.o core_math1.o core_math2.o core_phloat.o core_sto_rcl.o core_tables.o core_variables.o audio_alsa.o gcc111libbid.a -lgtk-3 -lgdk-3 -lz -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl -lpthread -ldl
/usr/lib/gcc/aarch64-alpine-linux-musl/13.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: cannot find gcc111libbid.a: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [Makefile:107: free42dec] Error 1
tomoqv commented 4 months ago

Oh, and here are some additional warnings early in the build:

shell_main.cc: In function 'int main(int, char**)':
shell_main.cc:386:57: warning: 'G_APPLICATION_FLAGS_NONE' is deprecated: Use 'G_APPLICATION_DEFAULT_FLAGS' instead [-Wdeprecated-declarations]
  386 |     app = gtk_application_new("com.thomasokken.free42", G_APPLICATION_FLAGS_NONE);
      |                                                         ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/glib-2.0/gio/giotypes.h:30,
                 from /usr/include/glib-2.0/gio/gio.h:28,
                 from /usr/include/gtk-3.0/gdk/gdkapplaunchcontext.h:28,
                 from /usr/include/gtk-3.0/gdk/gdk.h:32,
                 from /usr/include/gtk-3.0/gtk/gtk.h:30,
                 from shell_main.cc:18:
/usr/include/glib-2.0/gio/gioenums.h:1545:3: note: declared here
 1545 |   G_APPLICATION_FLAGS_NONE GIO_DEPRECATED_ENUMERATOR_IN_2_74_FOR(G_APPLICATION_DEFAULT_FLAGS),
      |   ^~~~~~~~~~~~~~~~~~~~~~~~
At global scope:
cc1plus: note: unrecognized command-line option '-Wno-unknown-warning-option' may have been intended to silence earlier diagnostics
cc1plus: note: unrecognized command-line option '-Wno-sometimes-uninitialized' may have been intended to silence earlier diagnostics
cc1plus: note: unrecognized command-line option '-Wno-constant-conversion' may have been intended to silence earlier diagnostics
thomasokken commented 4 months ago

From your post, it looks like you didn't just add the option I suggested, but you also deleted the exclamation point at the start of that line.

That's not going to work. You have only add that one option on line 16, and make no other changes. You can tell from the output you posted that patch couldn't make sense of the modified file. The format of a patch is very specific, everything in it is important, even line endings.

tomoqv commented 4 months ago

Ok, I think I tried it with the exclamation mark first and didn't get it to work. Now the line reads exactly like this: ! _CFLAGS_CC := -fsigned-char -DBID_SIZE_LONG=8 -D_WCHAR_T_DEFINED but I still get this error:

In file included from src/bid_internal.h:39,
                 from src/bid_strtod.h:35,
                 from src/strtod32.c:30:
src/bid_functions.h:46:15: error: conflicting types for 'wchar_t'; have 'int'
   46 | typedef int   wchar_t;
      |               ^~~~~~~
In file included from /usr/include/stdlib.h:21,
                 from /usr/include/fortify/stdlib.h:23,
                 from src/bid_strtod.h:32:
/usr/include/bits/alltypes.h:15:18: note: previous declaration of 'wchar_t' with type 'wchar_t' {aka 'unsigned int'}
   15 | typedef unsigned wchar_t;
      |                  ^~~~~~~
gmake[1]: *** [makefile:356: strtod32.o] Error 1
gmake[1]: Leaving directory '/home/user/Dokument/Kod/free42/gtk/IntelRDFPMathLib20U1/LIBRARY'
mv: can't rename 'libbid.a': No such file or directory
thomasokken commented 4 months ago

I don't know how to fix this, I'm afraid. It's not an issue I've run into on the Linux distros I've worked with, and I don't know of any work-arounds for wchar_t issues other than the one I suggested.

tomoqv commented 4 months ago

Ok, I understand. I have been fiddling around a bit with the file bid_functions.h, trying to understand what is going on with the error message. After a sudo make cleaner, the file is only found here on my system:

/home/user/Dokument/Kod/free42/common/bid_functions.h

So, I tried commenting out the following that the build stumbles on, as it seems to be not applicable to my build:

// Fix system header issue on Sun solaris and define required type by ourselves
#if !defined(_WCHAR_T) && !defined(_WCHAR_T_DEFINED) && !defined(__QNX__)
 typedef int wchar_t;
#endif

After a fresh build with sudo make BCD_MATH=1 AUDIO_ALSA=1 I end up with three bid_functions.h:

/home/user/Dokument/Kod/free42/common/bid_functions.h
/home/user/Dokument/Kod/free42/gtk/bid_functions.h
/home/user/Dokument/Kod/free42/gtk/IntelRDFPMathLib20U1/LIBRARY/src/bid_functions.h

the latter from July 12, 2011. I don't understand where it gets that version of the file from?? That file still contains the suspicious code I wanted to comment out.

Do you think it would work if that code was commented out, and if so, how can I do that?

Thanks for your patience!

thomasokken commented 4 months ago

The bid_functions.h in 'common' is a copy of the bid_functions.h from IntelRDFPMathLib20U1.tar.gz. The one in 'common' is used when compiling the Free42 sources; the one in IntelRDFPMathLib20U1.tar.gz is used when building the Intel library. In order to modify the latter, you'll have to create a diff from the original version to your modified one, and add that to intel-lib-linux.patch. (Take a look at build-intel-lib.sh to get a better idea what takes place when that library is built.)

thomasokken commented 4 months ago

Like this:

intel-lib-linux.patch

Actually, I don't understand why adding -D_WCHAR_T_DEFINED wouldn't achieve the same thing, but it can't hurt to give it a try...

thomasokken commented 4 months ago

Come to think of it, did the -D_WCHAR_T_DEFINED show up in the compiler flags while the Intel library was being built? I just realized that if the output from uname -m isn't one of armv7, armv7l, i386, ppc, aarch64, arm64, or i86pc, neither intel-lib-unknown-32bit.patch nor intel-lib-unknown-64bit.patch will be applied, and so the change I suggested will have no effect. What do you get when you run uname -m ?

tomoqv commented 4 months ago

Hello again, I finally succeeded! This is what I did: 1) Extracted ..free42/inteldecimal/IntelRDFPMathLib20U1.tar.gz 2) Edited line 46 in IntelRDFPMathLib20U1/LIBRARY/src/bid_functions.h from typedef int wchar_t; to typedef unsigned wchar_t; 3) Copied the new bid_functions.h into IntelRDFPMathLib20U1/LIBRARY/src/ 4) Made a new archive with tar -czf IntelRDFPMathLib20U1.tar.gz IntelRDFPMathLib20U1 5) cd back to ..free42/gtk 3) sudo make cleaner 4) make BCD_MATH=1 AUDIO_ALSA=1

Skärmbild från 2024-04-30 12-16-15

thomasokken commented 4 months ago

Nice. Congratulations!