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

macOS x86_64 link failure #4958

Closed
sezero opened this issue Nov 14, 2021 · 18 comments
Closed

macOS x86_64 link failure #4958

sezero opened this issue Nov 14, 2021 · 18 comments
Assignees
Milestone

Comments

@sezero
Copy link
Contributor

sezero commented Nov 14, 2021

Undefined symbols for architecture x86_64:
  "___isOSVersionAtLeast", referenced from:
      _Cocoa_UpdateClipCursor in SDL_cocoawindow.o
      -[Cocoa_WindowListener mouseMoved:] in SDL_cocoawindow.o
      _IOS_JoystickGetCapabilities in SDL_mfijoystick.o
ld: symbol(s) not found for architecture x86_64
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

This is with building against 10.12 SDK.

@sezero sezero added the bug label Nov 14, 2021
@sezero sezero added this to the 2.0.18 milestone Nov 14, 2021
@slouken slouken self-assigned this Nov 15, 2021
@slouken
Copy link
Collaborator

slouken commented Nov 15, 2021

Oh yeah, that is why we don't use @available. I'll have to look up what the 10.12 compatible way of doing this is.

@slime73
Copy link
Contributor

slime73 commented Nov 15, 2021

You could wrap the @available blocks in an #ifdef checking for MAC_OS_X_VERSION_10_13 - I think some other code does that.

@slouken
Copy link
Collaborator

slouken commented Nov 15, 2021

Can you verify this is fixed by cc094f4?

@sezero
Copy link
Contributor Author

sezero commented Nov 16, 2021

Still not fully resolved.

i686 build against 10.8 SDK:

src/joystick/iphoneos/SDL_mfijoystick.m:1342:27: warning: unused variable 'controller' [-Wunused-variable]
            GCController *controller = device->controller;
                          ^
1 warning generated.
Undefined symbols for architecture i386:
  "___isOSVersionAtLeast", referenced from:
      _IOS_JoystickGetCapabilities in SDL_mfijoystick.o
ld: symbol(s) not found for architecture i386
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

x86_64 build against 10.12 SDK:

src/joystick/iphoneos/SDL_mfijoystick.m:1342:27: warning: unused variable 'controller' [-Wunused-variable]
            GCController *controller = device->controller;
                          ^
1 warning generated.
Undefined symbols for architecture x86_64:
  "___isOSVersionAtLeast", referenced from:
      _IOS_JoystickGetCapabilities in SDL_mfijoystick.o
ld: symbol(s) not found for architecture x86_64
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

SDL_mfijoystick.m needs fixing.

@sezero
Copy link
Contributor Author

sezero commented Nov 17, 2021

Oh yeah, that is why we don't use @available. I'll have to look up what the 10.12 compatible way of doing this is.

You could wrap the @available blocks in an #ifdef checking for MAC_OS_X_VERSION_10_13

SDL_render_metal.m does that with @available for vsync -- maybe it can be changed too along the way...

@sezero
Copy link
Contributor Author

sezero commented Nov 21, 2021

Speaking of SDL_render_metal.m, building against 10.13 SDK fails
with missing symbols from it too:

Undefined symbols for architecture x86_64:
  "___isOSVersionAtLeast", referenced from:
      _METAL_CreateRenderer in SDL_render_metal.o
      _METAL_SetVSync in SDL_render_metal.o
      _IOS_JoystickGetCapabilities in SDL_mfijoystick.o
ld: symbol(s) not found for architecture x86_64
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

So we need fixing SDL_render_metal.m (which should be easy
using NSAppKitVersionNumber instead of @available) and also
SDL_mfijoystick.m (not exactly sure about how, considering it
checks for ios and tvos along with macos.)

@sezero
Copy link
Contributor Author

sezero commented Nov 21, 2021

Is the following OK for SDL_render_metal.m?
(I guess there is no way to get rid of MAC_OS_X_VERSION_10_13 ifdefs.)

diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m
index e4dd590..96f87ae 100644
--- a/src/render/metal/SDL_render_metal.m
+++ b/src/render/metal/SDL_render_metal.m
@@ -35,6 +35,10 @@
 #import <AppKit/NSView.h>
 #endif
 
+#ifndef NSAppKitVersionNumber10_13
+#define NSAppKitVersionNumber10_13 1561
+#endif
+
 /* Regenerate these with build-metal-shaders.sh */
 #ifdef __MACOSX__
 #include "SDL_shaders_metal_osx.h"
@@ -1584,7 +1588,7 @@ static int
 METAL_SetVSync(SDL_Renderer * renderer, const int vsync)
 {
 #if (defined(__MACOSX__) && defined(MAC_OS_X_VERSION_10_13)) || TARGET_OS_MACCATALYST
-    if (@available(macOS 10.13, *)) {
+    if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_13) {
         METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
         if (vsync) {
             data.mtllayer.displaySyncEnabled = YES;
@@ -1855,7 +1859,7 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
     renderer->always_batch = SDL_TRUE;
 
 #if (defined(__MACOSX__) && defined(MAC_OS_X_VERSION_10_13)) || TARGET_OS_MACCATALYST
-    if (@available(macOS 10.13, *)) {
+    if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_13) {
         data.mtllayer.displaySyncEnabled = (flags & SDL_RENDERER_PRESENTVSYNC) != 0;
         if (data.mtllayer.displaySyncEnabled) {
             renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;

@slime73
Copy link
Contributor

slime73 commented Nov 21, 2021

According to the Xcode release notes, the @available keyword was introduced in Xcode 9 along with the macOS 10.13 SDK. What's your Xcode setup? I'm surprised it's breaking for you if the release notes are accurate.

@sezero
Copy link
Contributor Author

sezero commented Nov 21, 2021

According to the Xcode release notes, the @available keyword was introduced in Xcode 9 along with the macOS 10.13 SDK. What's your Xcode setup? I'm surprised it's breaking for you if the release notes are accurate.

Cross-compiling on Linux using clang-5.0.2 or clang-11.1 or clang-12.0.1, and cctools-port (see https://github.com/tpoechtrager/cctools-port, I'm using the latest), against relevant MacOSX SDKs (downloadable from https://github.com/alexey-lysiuk/macos-sdk)

@slime73
Copy link
Contributor

slime73 commented Nov 21, 2021

Does that mean there's a bug in one of those non-standard tools? It's not gonna be very developer-friendly to have to work around upstream issues in non-sanctioned tools when writing macOS code for SDL, if so.

@sezero
Copy link
Contributor Author

sezero commented Nov 21, 2021

Does that mean there's a bug in one of those non-standard tools?

Don't think so, but I can't be sure, of course.

@slime73
Copy link
Contributor

slime73 commented Nov 21, 2021

Where is the issue coming from then? Given the official 10.13 SDK and Xcode 9+ tools do provide @available, so (as far as I know) the code should compile and link when using Xcode 9+.

@sezero
Copy link
Contributor Author

sezero commented Nov 21, 2021

Where is the issue coming from then? Given the official 10.13 SDK and Xcode 9+ tools do provide @available, so (as far as I know) the code should compile and link when using Xcode 9+.

As I said, I can't be sure. If it matters, here is how I invoke clang:

clang -target x86_64-apple-darwin9 -arch x86_64 -mlinker-version=609 -isysroot /opt/MacOSX10.13.sdk -B /opt/cctools-port/bin -mmacosx-version-min=10.6 <other stuff>

@sezero
Copy link
Contributor Author

sezero commented Nov 21, 2021

@slime73: https://jonnyzzz.com/blog/2018/06/05/link-error-2/ provided some insight: Since I'm targeting 10.6 as the minimum, @available macOS 10.13, *) is not optimized away, hence the linkage failure. I possibly need to include libclang_rt.osx.a among the link libs, but since I'm on linux that's not an easy option (I can always do it manually or compile builtins/os_version_check.c from the compiler_rt source myself, but it would be easier for me if we didn't depend on @available if possible.

@slime73
Copy link
Contributor

slime73 commented Nov 21, 2021

@available has been Apple's recommended Objective-C language feature for version detection for several years now. I'll go with whatever Sam and Ryan decide, but if contributors have to use hackier code instead of idiomatic language syntax then ultimately it'll add friction and extra time investment to SDL's development. It doesn't seem worth it to me if the purpose is to work around a problem with a third party build setup that can be addressed in that build setup instead.

@sezero
Copy link
Contributor Author

sezero commented Nov 21, 2021

FWIW, copying the clang_rt libs from the prebuilt darwin version of clang12 to proper place (<clangdir>/lib/clang/12.0.1/lib/) in the linux installation seems to 'fix' the issue.

@sezero
Copy link
Contributor Author

sezero commented Nov 21, 2021

With libclang_rt.osx.a in place, I have no issues. However, building
using older Xcode will still be a problem in SDL_mfijoystick.m. The
following patch will fix that. @slime73, @slouken: OK to apply and close
this?

diff --git a/src/joystick/iphoneos/SDL_mfijoystick.m b/src/joystick/iphoneos/SDL_mfijoystick.m
index 08ed418a1..605651f57 100644
--- a/src/joystick/iphoneos/SDL_mfijoystick.m
+++ b/src/joystick/iphoneos/SDL_mfijoystick.m
@@ -1329,38 +1329,40 @@ IOS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 ri
 static Uint32
 IOS_JoystickGetCapabilities(SDL_Joystick *joystick)
 {
     Uint32 result = 0;
 
+#if defined(ENABLE_MFI_LIGHT) || defined(ENABLE_MFI_RUMBLE)
     @autoreleasepool {
         SDL_JoystickDeviceItem *device = joystick->hwdata;
 
         if (device == NULL) {
             return 0;
         }
 
         if (@available(macos 11.0, iOS 14.0, tvOS 14.0, *)) {
             GCController *controller = device->controller;
-#ifdef ENABLE_MFI_LIGHT
+            #ifdef ENABLE_MFI_LIGHT
             if (controller.light) {
                 result |= SDL_JOYCAP_LED;
             }
-#endif /* ENABLE_MFI_LIGHT */
+            #endif
 
-#ifdef ENABLE_MFI_RUMBLE
+            #ifdef ENABLE_MFI_RUMBLE
             if (controller.haptics) {
                 for (GCHapticsLocality locality in controller.haptics.supportedLocalities) {
                     if ([locality isEqualToString:GCHapticsLocalityHandles]) {
                         result |= SDL_JOYCAP_RUMBLE;
                     } else if ([locality isEqualToString:GCHapticsLocalityTriggers]) {
                         result |= SDL_JOYCAP_RUMBLE_TRIGGERS;
                     }
                 }
             }
-#endif /* ENABLE_MFI_RUMBLE */
+            #endif
         }
     }
+#endif /* ENABLE_MFI_LIGHT || ENABLE_MFI_RUMBLE */
 
     return result;
 }
 
 static int

@sezero
Copy link
Contributor Author

sezero commented Nov 22, 2021

@slime73, @slouken: Applied ee2afa0 which fixes #4992 too. Closed the bug.

cknave added a commit to cknave/kevedit that referenced this issue Mar 8, 2023
Alpine base image to 3.17.2
osxcross to 6525b2b7d33abc371ad889f205377dc5cf81f23e: it now handles
fetching and building many dependencies automatically, and needs much
less (but still some) hackery to get it to build in a musl environment
(looking at you, pbzx).

macOS SDK to 11.3 (from Xcode 12.5.1).

Include compiler-rt to fix building more recent SDL versions (see
libsdl-org/SDL#4958).

Deployment target is now 10.7 due to SDL requirement.
cknave added a commit to cknave/kevedit that referenced this issue Mar 9, 2023
Alpine base image to 3.17.2
osxcross to 6525b2b7d33abc371ad889f205377dc5cf81f23e: it now handles
fetching and building many dependencies automatically, and needs much
less (but still some) hackery to get it to build in a musl environment
(looking at you, pbzx).

macOS SDK to 11.3 (from Xcode 12.5.1).

Include compiler-rt to fix building more recent SDL versions (see
libsdl-org/SDL#4958).

Deployment target is now 10.7 due to SDL requirement.
cknave added a commit to cknave/kevedit that referenced this issue Mar 9, 2023
Alpine base image to 3.17.2
osxcross to 6525b2b7d33abc371ad889f205377dc5cf81f23e: it now handles
fetching and building many dependencies automatically, and needs much
less (but still some) hackery to get it to build in a musl environment
(looking at you, pbzx).

macOS SDK to 11.3 (from Xcode 12.5.1).

Include compiler-rt to fix building more recent SDL versions (see
libsdl-org/SDL#4958).

Deployment target is now 10.7 due to SDL requirement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants