简体   繁体   中英

Xcode : executable does not find SDL2.framework

I'm trying to create an executable from my SDL2-Project, wich will run on any Mac that I send it to.

My Program is written in C++, Xcode9.2

Apparently the way to go in Xcode is Project->Archive. This works perfectly fine as long as I execute the product on my mac. On a mac that does not have the SDL2.framework installed under /Library/Frameworks/ it throws following error upon execution:

dyld: Library not loaded: @rpath/SDL2.framework/Versions/A/SDL2
Referenced from: /Users/thomas/Downloads/Chat_Program_Mac v1/Chat_Program 2
Reason: image not found

So this error is not very surprising, as I haven't linked statically (wouldn't know how this works anyways) and obviously the program needs the framework(s) to run.

On Windows you simply put the .dll files in the same folder as the .exe and that works.
Now on mac, putting the frameworks in the same folder as the executable won't change anything.

From my research I know, that in Xcode under BuildSettings->"Framework Search Paths" there is the option to tell the compiler where to look for the frameworks.

Someone on this forum answered to a similar question to put ./ as search path and set it to recursive to let the compiler look for the frameworks in the same folder, where the executable is.

This somehow got me closer to the solution. During the build process Xcode now looks for the frameworks inside the debug folder and creates the executable without error, while there are no SDL frameworks in /Library/Frameworks/.

EDIT: this does not work for Project->Archive. Even though I put the frameworks into the release folder. (/Users/Tim/Library/Developer/Xcode/DerivedData/Chat_Program-gapnuzuivnylrgbubtywdbzshous/Build/Products/Release)

When I try to run the executable though, the same error appears saying the library couldn't be loaded.
The executable does run though, if I put the frameworks back into /Library/Frameworks/, which tells me there must be an option to tell Xcode where the executable has to search for frameworks, that is not the BuildSettings->"Framework Search Paths" of the project.

So how do I tell my executable to look for the framework inside it's own folder?

So here's how I solved my problem:

  1. Goto BuildSettings->All->Linking->Runpath Search Paths
  2. Change to "@loader_path/"

Apparently this changes @rpath in the error message above to the path where the executable is, so the framework(s) can now be put into the same folder as the executable.

Pretty simple actually, maybe I'm an idiot that I had to research a whole day to find this. Maybe it's just very well hidden and kept as secret as possible even on the internet...

Whatever - happy it works now :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM