Why Can't the Linker Find SDL2 When the XCode Editor Can? (C, Apple Silicon)

54 Views Asked by At

So, I've been trying to use SDL2 with C for a while, and I've checked many other forum posts that don't help.

When editing the c file, the XCode editor finds SDL2/SDL.h fine, but when I go to run it, it fails with exit code 1:

/Users/<username>/Library/Developer/Xcode/DerivedData/3D?-erkhscnzezhtcwacawddllxsmicc/Build/Products/Debug/3D? normal (in target '3D?' from project '3D?')
    cd /Users/<username>/Desktop/3D\?
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -Xlinker -reproducible -target arm64-apple-macos14.2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -O0 -L/Users/<username>/Library/Developer/Xcode/DerivedData/3D\?-erkhscnzezhtcwacawddllxsmicc/Build/Intermediates.noindex/EagerLinkingTBDs/Debug -L/Users/<username>/Library/Developer/Xcode/DerivedData/3D\?-erkhscnzezhtcwacawddllxsmicc/Build/Products/Debug -F/Users/<username>/Library/Developer/Xcode/DerivedData/3D\?-erkhscnzezhtcwacawddllxsmicc/Build/Intermediates.noindex/EagerLinkingTBDs/Debug -F/Users/<username>/Library/Developer/Xcode/DerivedData/3D\?-erkhscnzezhtcwacawddllxsmicc/Build/Products/Debug -filelist /Users/<username>/Library/Developer/Xcode/DerivedData/3D\?-erkhscnzezhtcwacawddllxsmicc/Build/Intermediates.noindex/3D\?.build/Debug/3D\?.build/Objects-normal/arm64/3D\?.LinkFileList -Xlinker -rpath -Xlinker /opt/homebrew/include/ -Xlinker -object_path_lto -Xlinker /Users/<username>/Library/Developer/Xcode/DerivedData/3D\?-erkhscnzezhtcwacawddllxsmicc/Build/Intermediates.noindex/3D\?.build/Debug/3D\?.build/Objects-normal/arm64/3D\?_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/<username>/Library/Developer/Xcode/DerivedData/3D\?-erkhscnzezhtcwacawddllxsmicc/Build/Intermediates.noindex/3D\?.build/Debug/3D\?.build/Objects-normal/arm64/3D\?_dependency_info.dat -o /Users/<username>/Library/Developer/Xcode/DerivedData/3D\?-erkhscnzezhtcwacawddllxsmicc/Build/Products/Debug/3D\?

ld: Undefined symbols:
  _SDL_CreateRenderer, referenced from:
      _main in main.o
  _SDL_CreateTexture, referenced from:
      _main in main.o
  _SDL_CreateWindow, referenced from:
      _main in main.o
  _SDL_DestroyRenderer, referenced from:
      _main in main.o
  _SDL_DestroyTexture, referenced from:
      _main in main.o
  _SDL_DestroyWindow, referenced from:
      _main in main.o
  _SDL_GetError, referenced from:
      _main in main.o
      _main in main.o
      _main in main.o
      _main in main.o
  _SDL_GetKeyboardState, referenced from:
      _main in main.o
  _SDL_Init, referenced from:
      _main in main.o
  _SDL_PollEvent, referenced from:
      _main in main.o
  _SDL_RenderCopyEx, referenced from:
      _main in main.o
  _SDL_RenderPresent, referenced from:
      _main in main.o
  _SDL_UpdateTexture, referenced from:
      _main in main.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

(Note: what is above is the invocation)

Everything it is erroring on is due to the linker not finding SDL.h.

I have tried using terminal to compile, and have used both clang and gcc, both gave the same result. I tried appending -lsdl2, but that didn't work.

I have also tried adding the SDL2 header files to my project and accessing it locally, but none of the following worked:

#include <SDL2/SDL> <- finds this in editor

#include "SDL2/SDL" <- finds this in editor

#include "./SDL2/SDL.h" <- finds this in editor

#include "../../../../opt/homebrew/include/SDL2/SDL.h" <- finds this in editor

Although the editor finds the header files and lets me use them, whenever I try to run, it fails.

I have successfully compiled, assembled, and analyzed my file without errors.

Any help is greatly appreciated.

0

There are 0 best solutions below