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

Link error on Apple mobile targets #506

Open
Ravbug opened this issue Jan 23, 2025 · 5 comments
Open

Link error on Apple mobile targets #506

Ravbug opened this issue Jan 23, 2025 · 5 comments

Comments

@Ravbug
Copy link

Ravbug commented Jan 23, 2025

I'm adding an SDL_Image demo to SDL3 Sample. When building for iOS, tvOS and visionOS I get this linker error:

Undefined symbols for architecture arm64:
  "_CGImageSourceCreateImageAtIndex", referenced from:
      _LoadImageFromIOStream in libSDL3_image.a[3](IMG_ImageIO.o)
      _IMG_Load in libSDL3_image.a[3](IMG_ImageIO.o)
  "_CGImageSourceCreateWithDataProvider", referenced from:
      _Internal_isType in libSDL3_image.a[3](IMG_ImageIO.o)
      _LoadImageFromIOStream in libSDL3_image.a[3](IMG_ImageIO.o)
  "_CGImageSourceCreateWithURL", referenced from:
      _IMG_Load in libSDL3_image.a[3](IMG_ImageIO.o)
  "_CGImageSourceGetType", referenced from:
      _Internal_isType in libSDL3_image.a[3](IMG_ImageIO.o)
  "_UTTypeConformsTo", referenced from:
      _Internal_isType in libSDL3_image.a[3](IMG_ImageIO.o)
  "_kCGImageSourceTypeIdentifierHint", referenced from:
      _Internal_isType in libSDL3_image.a[3](IMG_ImageIO.o)
      _LoadImageFromIOStream in libSDL3_image.a[3](IMG_ImageIO.o)
  "_kUTTypeGIF", referenced from:
      _IMG_isGIF in libSDL3_image.a[3](IMG_ImageIO.o)
      _IMG_LoadGIF_IO in libSDL3_image.a[3](IMG_ImageIO.o)
  "_kUTTypeTIFF", referenced from:
      _IMG_isTIF in libSDL3_image.a[3](IMG_ImageIO.o)
      _IMG_LoadTIF_IO in libSDL3_image.a[3](IMG_ImageIO.o)
ld: symbol(s) not found for architecture arm64

I was able to fix it in SDL3 Sample by explicitly linking ImageIO and CoreServices:

if (APPLE)
	find_library(IO_LIB ImageIO)
 	find_library(CS_LIB CoreServices)
	target_link_libraries(${EXECUTABLE_NAME} PUBLIC ${IO_LIB} ${CS_LIB})
endif()

Is it expected for users to link these libraries? Or should SDL_Image be linking them automatically?

@slouken
Copy link
Collaborator

slouken commented Jan 23, 2025

@slouken slouken closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2025
@madebr
Copy link
Contributor

madebr commented Jan 23, 2025

The error is still valid: using static libraries should still work.

here
You need to put SDL3::SDL3 last.

@slouken
Copy link
Collaborator

slouken commented Jan 23, 2025

The error is still valid: using static libraries should still work.

here You need to put SDL3::SDL3 last.

The problem is that if you statically link SDL_image you need to link all the frameworks it uses in the application, which is what @Ravbug's fix is doing. But really we shouldn't be statically linking it.

(You probably also need to put SDL3 last, but that's separate from this issue)

@madebr
Copy link
Contributor

madebr commented Jan 23, 2025

The problem is that if you statically link SDL_image you need to link all the frameworks it uses in the application, which is what @Ravbug's fix is doing. But really we shouldn't be statically linking it.

You're right: SDL3 should be used as a shared library.

But CMake should handle static libraries for us: it propagates these to the final shared library or executable.
This is also why you can use SDL3::SDL3-static in your windows project without having to add the various win32 import libraries.
When we do target_link_options(SDL3_image-static PRIVATE -Wl,-framework,ImageIO), it should appear in the link command of ${EXECUTABLE_NAME}.

@slouken slouken reopened this Jan 23, 2025
@slouken
Copy link
Collaborator

slouken commented Jan 23, 2025

Ah, in that case, we probably need to do something like that in the SDL_image CMakeLists.txt for those frameworks. Can you take a look?

@slouken slouken added this to the 3.2.0 milestone Jan 23, 2025
@slouken slouken removed this from the 3.2.0 milestone Feb 1, 2025
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