0

I am trying to set up Xcode5 to create a C++ application which uses the libspotify.framework SDK. I have tried several combinations of adding the framework to the build phases, changing search paths, etc. The program will build but it fails at runtime throwing an error (below).

So far, in my programming experience, I have been able to link static libraries into Xcode C++ programs, but this is the first time I am trying to link a *.framework library into a C++ program.

Can anyone point out the step-by-step instructions on how to include a *.framework in a simple C++ console application? I'm pretty sure this is a "C" library so it should be possible, right?

Simple program:

#include <iostream>
#include "api.h"

int main(int argc, const char * argv[])
{
    // do some simple thing with the api
    return 0;
}

Runtime Error:

dyld: Library not loaded: @loader_path/../Frameworks/libspotify.framework/libspotify
Referenced from: /Users/mjb/Desktop/SpotifyTest/DerivedData/SpotifyTest/Build/Products/Debug/SpotifyTest Reason: image not found Program ended with exit code: 9(lldb)

Screenshot of the Xcode Project: Screenshot of the Xcode Project

Daxesh Nagar
  • 1,405
  • 14
  • 22
Matthew James Briggs
  • 2,085
  • 2
  • 28
  • 58
  • It looks like that the framework is expecting to be in the Frameworks folder of a .app bundle with the app binary located in it's usual .app location, however you are using a command-line tool target. You're also linking against the libspotify image itself rather than the .framework. – BergQuester Jun 01 '14 at 05:52
  • possible duplicate of [using frameworks in a command line tool](http://stackoverflow.com/questions/630911/using-frameworks-in-a-command-line-tool) – BergQuester Jun 01 '14 at 05:54
  • There are step-by-step instructions in the libspotify package root folder in `README`. It says Xcode 4, but it works for Xcode 5 too – paddy Jun 03 '14 at 05:46

1 Answers1

1

Follow the instructions from the README file provided with libspotify. I have included these below:

  1. Drag and drop libspotify.framework to the "Frameworks" group in the project navigator. Check "Copy items into destination groups's folder (if needed)".

  2. In the project navigator, select your project. Select your target and select the "Build Phases" tab.

  3. Click on "Add Build Phase->Add Copy files".

  4. Select Destination "Frameworks" in the "Copy Files" group.

  5. You probably want to rename this build phase by double clicking on the title. Name it something like "Copy Frameworks".

  6. Drag libspotify.framework from the project navigator and drop it in the "Copy Frameworks" group.

  7. Build. You can confirm that the above worked by right-clicking on your .app under Products in the project navigator and and selecting "Show in Finder" in the menu. Right-click on the application bundle and choose "Show Package Contents". Verify that have a Contents/Frameworks/libspotify.framework folder in there.

When you include the API header, do it like this:

#include <libspotify/api.h>
paddy
  • 60,864
  • 6
  • 61
  • 103
  • Thanks, I didn't realize these instructions were in the downloaded materials. Unfortunately I have never built an .app bundle and only know how to write C++ console apps and static libraries, so I'm not sure if these steps are applicable. – Matthew James Briggs Jun 04 '14 at 06:07
  • 1
    If you're not making an standard Mac OS X app package, you're going to have a bit of a rough time - libspotify and many Mac OS X frameworks are designed to be part of an app package. The answer linked in a comment above will get you on the right path, but if you're going to distribute this application I seriously suggest you build your app in the Mac OS X standard way of using a package - users don't like you installing frameworks all over the system. – iKenndac Jun 04 '14 at 19:48