joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.76k stars 381 forks source link

Problem with SDL2 macOS build #2199

Open emendelson opened 3 years ago

emendelson commented 3 years ago

This is slightly complicated, but here goes:

If I build current code for SDL1 under macOS Big Sur (on Intel), the build runs perfectly when I run it in macOS Mojave.

But if I build current code for SDL2 under Big Sur, it runs perfectly under Big Sur, but crashes in Mojave with this error:

Dyld Error Message:
  Symbol not found: _objc_opt_class
  Referenced from: /Users/USER/Desktop/dosbox-x (which was built for Mac OS X 11.0)
  Expected in: /usr/lib/libobjc.A.dylib

Is there a way to tell the build script to build for earlier versions of macOS? Again, this problem doesn't occur with the SDL1 build.

Wengier commented 3 years ago

@emendelson I do not have macOS Big Sur, but maybe this will help?

https://forum.juce.com/t/plugin-fails-to-resolve-symbol-in-libc-in-older-version-of-mac-than-the-build-host/41083

emendelson commented 3 years ago

@Wengier Yes - that's exactly what I would hope could be done for the code. But I can't figure out how to modify either the build script or anything else to specify the build-for version. I hope someone here might know the answer.

(PS I no longer have a Mojave build environment, so I'm only able to build SDL1, not SDL2, for macOS versions earlier than Big Sur. That doesn't affect my DOSBox-X-based Mac projects, which use SDL1 anyway, but I won't be able to build SDL2 versions for distribution from this site.)

Wengier commented 3 years ago

@emendelson Have you tried to set CMAKE_OSX_DEPLOYMENT_TARGET for the macOS target version? You can find some answers related to this below:

https://stackoverflow.com/questions/34208360/cmake-seems-to-ignore-cmake-osx-deployment-target

https://stackoverflow.com/questions/55254398/why-the-cmake-osx-deployment-target-not-work-when-using-cmake-generate-xcode-pro

emendelson commented 3 years ago

I added this line to the top of every cmakelists.txt file in the code:

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version")

The same crash still occurred in Mojave.

Wengier commented 3 years ago

@emendelson Have you tried adding FORCE in the end as mentioned in a link above?

emendelson commented 3 years ago

@Wengier That didn't work either. I still get this error:

Dyld Error Message:
  Symbol not found: _objc_opt_class
  Referenced from: /Users/USER/Desktop/dosbox-x (which was built for Mac OS X 11.0)
  Expected in: /usr/lib/libobjc.A.dylib
Wengier commented 3 years ago

@emendelson Since I am not really familiar with macOS, you may want to ask it in the StackOverFlow discussion, which may be helpful. Apparently this issue is not specific to DOSBox-X.

emendelson commented 3 years ago

@Wengier - Have asked, but no reply yet.

joncampbell123 commented 3 years ago

I'm able to compile on Mac OS X just fine. Can you try just using git clean -dfx and git reset to clean up your copy, and then run build-macosx again?

emendelson commented 3 years ago

@joncampbell123 - It compiles just fine. The problem is this: if I run build-macosx-sdl2 to compile SDL2 on Big Sur, the resulting executable runs perfectly under Big Sur and Catalina. But if I run the same executable under Mojave, it crashes when I type anything at the DOS prompt. This makes it impossible to compile an SDL2 version on Big Sur that can be used by anyone with Mojave (and presumably also with earlier versions, though I haven't tested this).

This problem does not happen if I compile SDL1. The executable compiled under Big Sur runs perfectly in Mojave. The problem only occurs with SDL2. The error message is in one of my earlier posts.

joncampbell123 commented 3 years ago

@emendelson Bizarre, I thought Mac OS X would be more forward compatible than that. Maybe it's an issue with SDL2?

As I don't have those older versions of OS X around anymore, I can't debug that myself.

If you run SDL2 builds from the OS X equivalent of gdb and let it crash that way, does the backtrace give any clues?

emendelson commented 3 years ago

As I don't have those older versions of OS X around anymore, I can't debug that myself.

If you run SDL2 builds from the OS X equivalent of gdb and let it crash that way, does the backtrace give any clues?

@joncampbell123 - I have older versions running in Parallels Desktop and VMware Fusion, not on hardware. If you have either one, it's fairly easy to install the older versions, though it takes some effort to find the installers.

I'm afraid I don't know how to run the OS X equivalent of gdb (or any version of gdb), but I can try to teach myself and will report.

EDIT: I see how to install gdb in macOS:

https://stackoverflow.com/questions/41966073/how-to-install-gdb-on-macos-terminal-sierra

Any hints on how to use it will be welcome. EDIT: It sounds like a major operation to do in the VMware Fusion Mojave installation that I've been using. I may not be able to get to this for a long time, as I'm also teaching in a university full-time. I hope someone more expert in macOS might be interested also.