Archive for the ‘Uncategorized’ Category

What I’ve learned over the past 2 days trying to get LibSVM 3.11 for Matlab installed on a Mac running OS X Lion

December 6, 2011

LibSVM comes as software package written in C. To get it to work with Matlab you need to compile it by typing “make” in the LibSVM/Matlab directory.

“make” will look for the C compiler on your computer and run it. The compiler’s name is g++ and is inside a software suite called XCode.

XCode is Apple’s set of tools for developers and does not come preinstalled on OSX.  Instead you have to download it.  Xcode 4.2 is free off the Mac App Store if you’re running Lion. If you’re running Snow Leopard, you need to register for free to get on the Apple developers website, where you can download XCode 3.2.6.

Knowing all this there are a bunch of different reasons why “make” could give you an error. The two I ran across are:

1. Xcode is not installed. If you have no Developer directory on your hard drive, you don’t have it.If this is the case you’ll get a few lines of error that look something like this:

/Applications/MATLAB_R2009aSV.app/bin/mex: line 1102: gcc-4.0: command not found
/Applications/MATLAB_R2009aSV.app/bin/mex: line 1081: gcc-4.0: command not found
/Applications/MATLAB_R2009aSV.app/bin/mex: line 992: gcc-4.0: command not found

Install XCode to fix this.

2.If you have XCode installed, you can still get errors if there are version conflicts between Xcode, Matlab, and OSX. Basically, all 3 have to match in order to for the makefile to work.  If they don’t, you’ll probably get some kind of giant block of scrolling text error.

svm.cpp:1:18: error: math.h: No such file or directory
svm.cpp:2:19: error: stdio.h: No such file or directory
svm.cpp:3:20: error: stdlib.h: No such file or directory
svm.cpp:4:19: error: ctype.h: No such file or directory
svm.cpp:5:19: error: float.h: No such file or directory
svm.cpp:6:20: error: string.h: No such file or directory
svm.cpp:7:20: error: stdarg.h: No such file or directory
svm.cpp: In function ‘void clone(T*&, S*, int)’:
svm.cpp:22: error: there are no arguments to ‘memcpy’ that depend on a template parameter, so a declaration of ‘memcpy’ must be available
svm.cpp:22: error: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
svm.cpp: In function ‘void print_string_stdout(const char*)’:
svm.cpp:41: error: ‘stdout’ was not declared in this scope
svm.cpp:41: error: ‘fputs’ was not declared in this scope
svm.cpp:42: error: ‘fflush’ was not declared in this scope
svm.cpp: In function ‘void info(const char*, …)’:
svm.cpp:48: error: ‘BUFSIZ’ was not declared in this scope
svm.cpp:49: error: ‘va_list’ was not declared in this scope
svm.cpp:49: error: expected `;’ before ‘ap’
svm.cpp:50: error: ‘ap’ was not declared in this scope
svm.cpp:50: error: ‘va_start’ was not declared in this scope
svm.cpp:51: error: ‘buf’ was not declared in this scope
svm.cpp:51: error: ‘vsprintf’ was not declared in this scope
svm.cpp:52: error: ‘va_end’ was not declared in this scope
svm.cpp: In constructor ‘Cache::Cache(int, long int)’:
ETC ETC ETC

I was running Matlab R2009a, OS X Lion, and didn’t have XCode installed.

I got the first error which was resolved by installing XCode 4.2

I then got the second error and found my version of Matlab was not compatible with 4.2.It was older and needed the 3.X revision (according to this nifty chart from Mathworks). So I uninstalled 4.2 and installed 3.2

I then got the second type of error again and yelled out WTF. Eventually I looked at the Developer/Library directory and realized half of the directories were empty. Found out that XCode Rev 3.2 is not supposed to be installed on Lion and if you try, it only does a partial install because Apple disabled the Toolkit installation for anything non-Lion. The Toolkit contains everything that’s important… including the uninstall script.

At this point, my choices were to either upgrade Matlab to the latest version and use XCode 4.2 and Lion, or use old version Matlab, XCode 3.2, and downgrade OS X to Snow Leopard.

My version of Matlab is the student version, but I’m not registered this semester so I couldn’t do the upgrade process (the one where they make you submit your fingerprints, 10 photo ID’s, and social security # just to get a license). So I sat there ready to downgrade OS X.

But lucky for me, I found a hack on the internet which let me install XCode Rev 3.2 on Lion. Thanks to Anatomic Wax for this. I have no clue who he is but he saved me a headache since I have no clue where my Snow Leopard disc is anyway.

Cheers

Advertisements