Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cocoadev

macrumors newbie
Original poster
Apr 6, 2010
6
0
Hi,

I am doing one project in which i need to identify the genre of the songs by Last.fm 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.
 
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?
 
I got this unix binary from this link: http://www.last.fm/user/nova77LF/journal/2007/10/12/4kaf_fingerprint_(command_line)_client

Code:
-(void)initializeTask
{
	/* 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

-(void)runTask
{
	[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];
}
Output:
---------------
ag,dylib
Referenced from: /Users/mac/Desktop/LastFm/build/Development/LastFm.app/Contents/Resource/lastfmfpclient
Reason: imgae not found
 
Did you read the readme.txt that came in the zip file?

It's a quick hack, since we did not want to bother about the libs, thus
make sure you are running it from the directory where the executable resides!

Cheers,
Last.fm MIR Team

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:
Code:
otool -L lastfmfpclient
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:
http://www.last.fm/user/nova77LF/journal/2007/10/12/4kaf_fingerprint_(command_line)_client
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.
 
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,

otool -L sox
sox:
/usr/local/lib/libvorbisfile.3.dylib (compatibility version 5.0.0, current version 5.0.0)
/usr/local/lib/libvorbisenc.2.dylib (compatibility version 3.0.0, current version 3.0.0)
/usr/local/lib/libvorbis.0.dylib (compatibility version 4.0.0, current version 4.0.0)
/usr/local/lib/libogg.0.dylib (compatibility version 6.0.0, current version 6.0.0)
/usr/local/lib/libmad.0.dylib (compatibility version 3.0.0, current version 3.1.0)
/usr/local/lib/libmp3lame.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libmx.A.dylib (compatibility version 1.0.0, current version 92.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.0.0)

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.
 
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.

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:
http://en.wikipedia.org/wiki/Working_directory
http://en.wikipedia.org/wiki/Path_(computing)

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.