Problem with Lastfmfpclient and NSTask

Discussion in 'Mac Programming' started by cocoadev, Apr 6, 2010.

  1. cocoadev macrumors newbie

    Apr 6, 2010

    I am doing one project in which i need to identify the genre of the songs by API.

    I need to use lastfmfpclient fingerprint api for this task.

    I got lastfmfpclient unix executable binary so i thought to use NSTask and do this task. I added all the library and it compiled also. But it gives me runtime error.

    I am getting following error for this.

    Reason: Image Not Found with lastfmfpclient

    Does anyone know that how to solve this problem with unix executable binary.

    Many Thanks.
  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    Where did you get this executable from? What OS/architectures is it compiled for? If you run lipo -info on it what do you get?
  3. cocoadev thread starter macrumors newbie

    Apr 6, 2010
  4. chown33 macrumors 604

    Aug 9, 2009
    What model of Mac do you have? In particular, is it Intel-based or PowerPC?

    Which OS version?
  5. cocoadev thread starter macrumors newbie

    Apr 6, 2010
    I used Intel-Based iMac with 10.5.8 OS version
  6. robbieduncan Moderator emeritus


    Jul 24, 2002
  7. cocoadev thread starter macrumors newbie

    Apr 6, 2010
  8. chown33 macrumors 604

    Aug 9, 2009
    Then post your code that uses NSTask. You have to show us exactly how you're running the command, including waiting for it to finish, reading any output, etc.
  9. cocoadev thread starter macrumors newbie

    Apr 6, 2010
    I got this unix binary from this link:

    	/* LAST FM CLIENT  */
    	NSString * toolPath;
    	toolPath = [[NSBundle mainBundle] pathForResource:@"lastfmfpclient" ofType:@""];
    	NSDictionary *defaultEnvironment = [[NSProcessInfo processInfo] environment];
    	NSMutableDictionary *environment = [[NSMutableDictionary alloc] initWithDictionary:defaultEnvironment];
    	task = [[NSTask alloc] init];
    	[task setLaunchPath:toolPath];
    	[environment setObject:@"YES" forKey:@"NSUnbufferedIO"];
    	[task setEnvironment:environment];
    	outputPipe = [NSPipe pipe];
    	taskOutput = [outputPipe fileHandleForReading];
    	[defaultCenter addObserver:self selector:@selector(taskDataAvailable:) name:NSFileHandleReadCompletionNotification object:taskOutput];
    	[task setStandardOutput:outputPipe];
    	[task setStandardError:outputPipe];
    	inputPipe = [NSPipe pipe];
    	taskInput = [inputPipe fileHandleForWriting];
    	[task setStandardInput:inputPipe];
    	[taskOutput readInBackgroundAndNotify];
    	[environment release];
    And this is the command : lastfmfpclient yourMp3File.mp3
    	[args retain];
    	NSString *filename = @"/Users/mac/Desktop/michael jackson.mp3";
    	NSMutableArray *mArray = [[NSMutableArray alloc] init];
    	[mArray addObject:filename];
    	[defaultCenter addObserver:self selector:@selector(taskCompleted:) name:NSTaskDidTerminateNotification object:task];
    	[task setArguments:mArray];
    	[mArray release];
    Referenced from: /Users/mac/Desktop/LastFm/build/Development/
    Reason: imgae not found
  10. chown33 macrumors 604

    Aug 9, 2009
    Did you read the readme.txt that came in the zip file?

    Your use of NSTask does not set the working directory to where the executable resides. Try that and see what happens. You will need to use -setCurrentDirectoryPath: on the NSTask before launching it. You will need to determine the correct directory, too.

    Further evidence that setting the working dir is required, this command and its output:
    otool -L lastfmfpclient
            ./libmad.dylib (compatibility version 3.0.0, current version 3.1.0)
            ./libtag.dylib (compatibility version 6.0.0, current version 6.0.0)
            ./libcurl.dylib (compatibility version 4.0.0, current version 4.0.0)
            ./libsamplerate.dylib (compatibility version 2.0.0, current version 2.1.0)
            /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.4.0)
            /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
            /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.3.9)
    Notice that the dylibs are referenced as relative pathnames, beginning with "./". Therefore, the dir where the executable resides must be the working dir, or the "./" pathname fragments won't work.

    I suspect the real error message said something like "libtag.dylib", and not "ag,dylib". Details matter. Copy and paste is your friend.

    And I don't see anything at this URL:
    that says anything about using it in NSTask.

    If you've never used NSTask before, then you might not understand everything you need to do. If you have, then you should understand about the working dir.
  11. cocoadev thread starter macrumors newbie

    Apr 6, 2010
    Thanks for the reply.

    Actually This NSTask code works fine with sox unix binary.

    I am using NSTask for first time and they haven't tell anything in the link which is given above. They have just given unix binary but i have to use this functionality in my project so i thought to use unix binary with NSTask.

    One more question, i did otool -L with sox unix library which work well and i got following output,

    And there is no library added related to sox in the project and all the library added in the /usr/local/lib and it works fine.

    But Lastfm binary gives different output, but still i added all the library into the project directly and it is not working same.

    I think i should attach full source code here. I will attach within some time.

    Thanks fot help.
  12. chown33 macrumors 604

    Aug 9, 2009
    Sox uses libraries that have absolute pathnames. That means it can be run with any value of working directory.

    lastfmfpclient uses libraries that have relative pathnames. That means it must be run with the working directory set to the same location as the executable lastfmfpclient itself.

    I don't think you understand the importance of this.

    I'm not sure you understand what a working directory is, either:

    What you need to understand is that the library pathnames like "./libmad.dylib" and "./libtag.dylib" that built into lastfmfpclient are relative to the working directory. They won't resolve properly unless you set the working directory of the NSTask before it's launched.

    Since sox has absolute pathnames, you don't need to do this. But sox is not built the same way as lastfmfpclient, so you can't assume that if your NSTask setup works for sox it will work for lastfmfpclient.

Share This Page