Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building on M1 Mac ... #33

Open
spock64 opened this issue Feb 9, 2022 · 9 comments
Open

Building on M1 Mac ... #33

spock64 opened this issue Feb 9, 2022 · 9 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@spock64
Copy link

spock64 commented Feb 9, 2022

Describe the Bug

I'm having trouble building the App on an M1 Mac !

Expected Behavior

A working build :-)

System

MacOS 12.2
pw3270 - either master or macos branch


Hi, I am trying to build the app but am hitting problems in the build. I'm following the simple instructions.

I have already built and installed lib3270 and libv3270 seemingly successfully.

First, the link step of 'make all' fails because it cannot locate the lib320 / libv3270 libraries. I have fixed this by adding the paths into the Makefile, and end up with a build.

The real issue comes when trying to use "bundle" - first there are a bunch of warnings related to signatures being invalidated due to changes being made to the file - for example:

/Library/Developer/CommandLineTools/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/j/Projects/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/im-viqr.so

These warnings seem to be harmless as far as the bundling is concerned ...

There are also errors related to some libraries not being found ...

My question is: how should I build the app? I have homebrew so do not want to go down the jhbuild route if possible.

Should I be using master or the macos branch to build?

Thanks!

@spock64 spock64 added the bug Something isn't working label Feb 9, 2022
@PerryWerneck PerryWerneck added the help wanted Extra attention is needed label Feb 10, 2022
@PerryWerneck
Copy link
Owner

PerryWerneck commented Feb 10, 2022

Hi,

Which libraries are not being found? I dont have much experience using MAC and just did a really small test in homebrew but, I think, it seens to be working for you since the app is built (did you tested if it runs fine before bundle it?)

For now, the best branch for mac is the macos branch because it has a few changes for macos (like changing GtkApplication for GtkOSXApplication and other small stuff).

@PerryWerneck PerryWerneck self-assigned this Feb 10, 2022
@spock64
Copy link
Author

spock64 commented Feb 10, 2022

Hi,

Here's a bit more detail ...

Building on M1 mac, Macos 12.2 - tried to build using jhbuild but this rapidly turned into a nightmare due to this tool not being up to date ... so I'm using homebrew.

I have built both lib3270 and libv3270 following the instructions. Some adjustments were needed to the generated Makefiles to add -I/opt/homebrew/include to CFLAGS and /opt/homebrew/lib to LIBS in both cases.

There was also an issued around libintl.h which meant setting environment variables to prevent autopen.sh from throwing up.

So far, so good.

Then - using the macOS branch - try to make, adding gtk-mac-integration as I go ... and adding the include and lib path to the generated Makefile ...

This ends up with a build.

I then try to bundle (without bundling we end up with complaints about not finding libraries), and this fails as bundle is trying to copy the wrong schema. So fix and rebundle. Oh, and codesign!

Then we can run the app - but by using the launcher.sh within the bundle.
This results in the lib3270 and libv3270 libraries not being found - which is an issue with the bundle script I think.

So, copy the libraries into the bundle (in Contents/Resources) and, after codesigning again, try launcher.sh.

Here's what I get ...

j@pauls-mac-mini MacOS % ./launcher.sh
allexport      	off
braceexpand    	on
emacs          	off
errexit        	on
errtrace       	off
functrace      	off
hashall        	on
histexpand     	off
history        	off
ignoreeof      	off
interactive-comments	on
keyword        	off
monitor        	off
noclobber      	off
noexec         	off
noglob         	off
nolog          	off
notify         	off
nounset        	on
onecmd         	off
physical       	off
pipefail       	off
posix          	on
privileged     	off
verbose        	off
vi             	off
xtrace         	off
objc[19773]: Class GNotificationCenterDelegate is implemented in both /opt/homebrew/Cellar/glib/2.70.3/lib/libgio-2.0.0.dylib (0x1068e46b0) and /Users/j/Documents/Projects/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgio-2.0.0.dylib (0x10533c6b0). One of the two will be used. Which one is undefined.
objc[19773]: Class GdkQuartzView is implemented in both /opt/homebrew/Cellar/gtk+3/3.24.30_1/lib/libgdk-3.0.dylib (0x1060990d8) and /Users/j/Documents/Projects/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgdk-3.0.dylib (0x104ad90d8). One of the two will be used. Which one is undefined.
objc[19773]: Class GdkQuartzNSWindow is implemented in both /opt/homebrew/Cellar/gtk+3/3.24.30_1/lib/libgdk-3.0.dylib (0x106099128) and /Users/j/Documents/Projects/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgdk-3.0.dylib (0x104ad9128). One of the two will be used. Which one is undefined.
objc[19773]: Class gdkCoreCursor is implemented in both /opt/homebrew/Cellar/gtk+3/3.24.30_1/lib/libgdk-3.0.dylib (0x106099178) and /Users/j/Documents/Projects/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgdk-3.0.dylib (0x104ad9178). One of the two will be used. Which one is undefined.
objc[19773]: Class GtkClipboardOwner is implemented in both /opt/homebrew/Cellar/gtk+3/3.24.30_1/lib/libgtk-3.0.dylib (0x107001cd0) and /Users/j/Documents/Projects/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgtk-3.0.dylib (0x105a59cd0). One of the two will be used. Which one is undefined.
objc[19773]: Class GtkDragSourceOwner is implemented in both /opt/homebrew/Cellar/gtk+3/3.24.30_1/lib/libgtk-3.0.dylib (0x107001d20) and /Users/j/Documents/Projects/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgtk-3.0.dylib (0x105a59d20). One of the two will be used. Which one is undefined.
objc[19773]: Class GtkQuartzStatusIcon is implemented in both /opt/homebrew/Cellar/gtk+3/3.24.30_1/lib/libgtk-3.0.dylib (0x107001d70) and /Users/j/Documents/Projects/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgtk-3.0.dylib (0x105a59d70). One of the two will be used. Which one is undefined.
objc[19773]: Class ResultReceiver is implemented in both /opt/homebrew/Cellar/gtk+3/3.24.30_1/lib/libgtk-3.0.dylib (0x107001de8) and /Users/j/Documents/Projects/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgtk-3.0.dylib (0x105a59de8). One of the two will be used. Which one is undefined.
objc[19773]: Class GtkApplicationQuartzDelegate is implemented in both /opt/homebrew/Cellar/gtk+3/3.24.30_1/lib/libgtk-3.0.dylib (0x107001e10) and /Users/j/Documents/Projects/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgtk-3.0.dylib (0x105a59e10). One of the two will be used. Which one is undefined.
objc[19773]: Class GNSMenuItem is implemented in both /opt/homebrew/Cellar/gtk+3/3.24.30_1/lib/libgtk-3.0.dylib (0x107001e60) and /Users/j/Documents/Projects/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgtk-3.0.dylib (0x105a59e60). One of the two will be used. Which one is undefined.
objc[19773]: Class GNSMenu is implemented in both /opt/homebrew/Cellar/gtk+3/3.24.30_1/lib/libgtk-3.0.dylib (0x107001e88) and /Users/j/Documents/Projects/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgtk-3.0.dylib (0x105a59e88). One of the two will be used. Which one is undefined.
objc[19773]: Class FilterComboBox is implemented in both /opt/homebrew/Cellar/gtk+3/3.24.30_1/lib/libgtk-3.0.dylib (0x107001f00) and /Users/j/Documents/Projects/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgtk-3.0.dylib (0x105a59f00). One of the two will be used. Which one is undefined.
GLib-GObject invalid class cast from 'pw3270Application' to 'GtkApplication'
GLib-GObject invalid class cast from 'pw3270Application' to 'GApplication'
GLib-GObject g_object_new_is_valid_property: object class 'pw3270Application' has no property named 'application-id'
GLib-GObject invalid cast from 'pw3270Application' to 'GApplication'
GLib-GIO g_application_add_main_option_entries: assertion 'G_IS_APPLICATION (application)' failed
GLib-GIO _g_io_module_get_default: Found default implementation nextstep (GNextstepSettingsBackend) for ‘gsettings-backend’
GLib-GObject invalid cast from 'pw3270Application' to 'GApplication'
GLib-GIO g_application_run: assertion 'G_IS_APPLICATION (application)' failed
j@pauls-mac-mini MacOS %

So, now the application is starting, but is failing to initialise.

I'm very, very rusty on gtk but will try to see what is happening.

Any hints would be very helpful!

@PerryWerneck
Copy link
Owner

Hi,

By the messages seens to be having a lot of duplicated 'dynlib's. I think you're building the pw3270 application using 'make all' am I right? Can you try test using 'make Debug' and 'make run' to see if it runs?

@PerryWerneck
Copy link
Owner

Hi,

Found the cause for the error 'GLib-GObject invalid class cast from 'pw3270Application' to 'GtkApplication''. On Mac pw3270Application is a GTKOSXApplication, not a GtkApplication. Will look at this ASAP.

@spock64
Copy link
Author

spock64 commented Feb 10, 2022

Hi,

Yes, I'm building with a simple "make all". Doing the "make Debug; make run", results in:

make run
dyld[98065]: Library not loaded: libv3270.dylib.5.4
  Referenced from: /Users/j/Projects/pw3270/pw3270/.bin/Debug/pw3270
  Reason: tried: 'libv3270.dylib.5.4' (no such file), '/usr/local/lib/libv3270.dylib.5.4' (no such file), '/usr/lib/libv3270.dylib.5.4' (no such file), '/Users/j/Projects/pw3270/pw3270/libv3270.dylib.5.4' (no such file), '/usr/local/lib/libv3270.dylib.5.4' (no such file), '/usr/lib/libv3270.dylib.5.4'

I think there's a couple of things going on here ...

  • The GTKOSXApplication / GtkApplication thing
  • The fact that when building on an M1 Mac there are a number of problems

I have tried to build on an x86 Mac earlier and the build process is cleaner than on an M1, but, as you spotted, ultimately the thing won't run because of the GTKOSXApplication/GtkApplication problem.

I'm happy to look at the M1 problems - which seem to be much wider than the specific app issue around using GTKOSXApplication.

I'll update you with specifics around the M1 stuff tomorrow.

I'll also try the debug build/run on my x86 Mac too.

@spock64
Copy link
Author

spock64 commented Feb 10, 2022

On duplicated dynlibs ... this is because there is a copy in the bundle and in the /opt/homebrew/Cellar/... folder.

It is odd that this is being complained about - probably an issue with the bundle script ?

@PerryWerneck
Copy link
Owner

Hi,

Adding some comments after the quotes...

Yes, I'm building with a simple "make all". Doing the "make Debug; make run", results in:
make run
dyld[98065]: Library not loaded: libv3270.dylib.5.4

It's not finding the libraries. Dont know how to do this on homebrew but, in jhbuild, the make run only works inside the 'jhbuild shell'

  • The GTKOSXApplication / GtkApplication thing

Already removed, it doesnt work anyway, I tried it to fix a problem with the top menu but, today I found this: https://stackoverflow.com/questions/67622779/cross-platform-gtk3-app-menu-bar-unresponsive-at-first and, maybe the problem doesn't happen when using a bundled application.

With the code in the macos branch I was able to build and run the app using jhbuild. Not tested the top menu yet; will do it tomorrow.

  • The fact that when building on an M1 Mac there are a number of problems
    I have tried to build on an x86 Mac earlier and the build process is cleaner than on an M1, but, as you spotted, ultimately the thing won't run because of the GTKOSXApplication/GtkApplication problem.
    I'm happy to look at the M1 problems - which seem to be much wider than the specific app issue around using GTKOSXApplication.

@spock64
Copy link
Author

spock64 commented Feb 12, 2022

Hi,

The libraries thing was just a comment on test running per your instructions ! Of course I can see what is going on ...

So, focussing on what is happening on the M1 build, I have a number of corrections to the macOS/bundle script - the issues I found building on an M1 mac were:

  1. The following flags are needed to allow the build to find libintl (part of the get text package):

LDFLAGS=$LDFLAGS -L/opt/homebrew/Cellar/gettext/0.21/lib
CFLAGS=-I/opt/homebrew/Cellar/gettext/0.21/include

These flags need to be set for the build of lib3270, libv3270 and pw3270 - I set them before running autogen.sh ...

  1. The script needs to use either /usr/local/lib (on x86) or /opt/homebrew/lib (on M1 / aarch64) when searching for dependencies - so I adjusted the definition of libs_path in find_lib() to be:

local libs_path="${HOME}/lib brew --prefix/lib /usr/lib"

  1. When copying in the schemas, the wrong files were being copied, so:

cp "../schemas/macos/"*".xml" "${tmp}/schemas"

  1. The pc3270.ui.xml file is required at runtime ... so ...

cp "../ui/macos.ui.xml" "${res_path}/pw3270.ui.xml"

  1. For some reason the libbrotlicommon library is not found by the bundle process, so I simply copy it in ...

cp "brew --prefix/Cellar/brotli/1.0.9/lib/libbrotlicommon.1.dylib" "${lib_path}/libbrotlicommon.1.dylib"

I have now built your latest macOS branches with the above and get a working binary ... although I would need to test it properly.

Btw, binaries need to be signed to run on M1, so ...

codesign --force --deep --sign - ./pw3270.app

I will give my version of macOS/bundle a try on my x86 Mac tomorrow to check that the build works there too.

Assuming that works, I will drop the changes over to you!

@wyan
Copy link

wyan commented Mar 26, 2022

So, I managed to figure out the LDFLAGS/CFLAGS issue to build 'lib3270' and 'libv3270', now I build 'pw3270' almost to the end, but the ./bundle part hangs with a missing system library:

❯ ./bundle
Creating temporary directory
Bundling GLib schemas
Creating app icon bundle
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/alice/projects/mainframe/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgtk-3.0.dylib
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/alice/projects/mainframe/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgtk-3.0.dylib
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/alice/projects/mainframe/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgdk-3.0.dylib
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/alice/projects/mainframe/pw3270/pw3270/macos/pw3270.app/Contents/Frameworks/libgdk-3.0.dylib
Lib /usr/lib/libSystem.B.dylib not found

This happens on both master and macos branches, and might have to do with changes in the way dynamic library loading happens in later macOS versions (see i.e. comments on golang/go#17490). I'm not sure what sort of fix this would need.

This is on macOS 12.3 on Apple Silicon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
Status: Backlog
Development

No branches or pull requests

3 participants