## Posts Tagged ‘10.6’

### ETH matlab license server, mac os x

Thursday, June 9th, 2011

I had already downloaded and installed MATLAB 2010b at NYU, so coming out here to ETH I didn’t want to bother reinstalling everything. I also didn’t want to have to VPN to NYU every time I wanted to use MATLAB. So instead I just switched my network license file to point to the ETH license server instead of the NYU one. This so far has worked out great. First thing I did was go the license directory in the matlab folder:

cd /Applications/MATLAB_R2010b.app/licenses/


Then I backed up my NYU license file:

mv network.lic network.lic.nyu


ETH license file, which is bizarrely named license.dat.mpg. Finally, I just moved this file to the proper place (current directory is the matlab license directory) with the proper name:

mv ~/Downloads/license.dat.mpg network.lic


### Add new ipp printer mac os x 10.6

Thursday, June 9th, 2011

In either system preferences > Print and Fax or via the drop down when choosing a printer in the printer dialog add a new printer. At the top there are 5 options, choose Advanced. Wait for it to do its thing. Then change type to Internet Printing Protocol. Device should stay as “Another Device”. In URL enter ipp://your.printers.ipp.address. Under Name, add the name you’d like the print to show up as in print dialogs. Finally change Print Using to “Auto Select”, it may change it back automatically to “Generic PostScript Printer” or something else.

### Mac OS X 10.6 VPN configuration error after wrong password

Wednesday, April 27th, 2011

The built-in VPN client in mac os x 10.6 annoyingly won’t remember passwords. I have to type it in every time I connect. What’s worse is that if I mistype it some how ruins the VPN client so that I can reconnect. When I try I don’t even make it to the password prompt. I just get:


A configuration error occured. Verify your settings and try reconnecting


I manage to restart the VPN client by issuing this in a Terminal:


sudo launchctl stop com.apple.racoon
sudo launchctl start com.apple.racoon


After that when I try, I get to the password prompt and I’m able to reconnect.

Similar idea here

### Mac OS X Snow Leopard VPN stops working

Monday, April 18th, 2011

All of a sudden my VPN client (the one built into Mac OS X 10.6) asked me for my password. I’d already been logged into the NYU VPN for a few hours. I accidentally clicked cancel.
I tried to reconnect, but now I kept getting this error:


A configuration error occurred. Verify your settings and try reconnecting.


The little icon in the corner would spin and read “Connecting…” but this error would pop up even before it prompted me for my username and password.

So in true Mac style I spent 20 minutes trying to figure out how I could fix this without restarting. (I’m sure restarting would have worked just fine).

Turns out VPN couldn’t connect because another similar process was (already) running. By opening up Terminal.app I issued:


ps -ef | grep racoon


and saw:


0 84139     1   0   0:00.06 ??         0:00.13 /usr/sbin/racoon


Then I issued:


sudo kill 84139


I reconnected VPN and all is well.

### During upgrade to snow leopard stuck on apple logo

Tuesday, March 15th, 2011

Yesterday I finally got around to updating the OS on my macbook pro from Leopard (mac os x 10.5) to Snow Leopard (mac os x 10.6). I had debated waiting until Lion (10.7), set to appear this summer, but while I would probably want to wait until it had stabilized in the fall and applications were already turning their backs on Leopard I decided to just give in early.

I bought the Snow Leopard DVD, inserted it, pushed start and let it go. For about 30 mins it had a standard dialog box and progress bar, reporting that it was busy unpacking and installing. Then it rebooted itself at hung on the apple logo start up screen for 3 hours.

I read a few other reports of this online and it seemed a lot of people had given up sooner than 3 hours and had lots of problems, so I let it go. The computer started getting warm after a few hours: the DVD drive seemed to be busy the entire time. Finally I gave up and held the power button to force a shutdown. When I restarted it never even got to the apple logo, just a grey screen.

At this point I really gave up. Being in New York, where there is a 24 hour apple store it’s easy to give up. I held the power button down to force another shutdown and biked my laptop to the Genius Bar.

There the clerk told me that the installation had paused for whatever reason only partly done. He force ejected the DVD then plugged in a Firewire drive and finished the installation booting from the Firewire device.

After 45 mins everything was installed and so far everything has been working fine.

### Compiling, installing and using AntTweakBar on Mac OS X

Monday, August 30th, 2010

Seeing Bruno Levy‘s demos at SIGGRAPH 2010 convinced me that I want to start using the painlessly easy prototyping GUI library, AntTweakBar. The premise of AntTweakBar is great. Prototyping should be easy and a researcher shouldn’t spend any time on UI that just flips flags and changes input parameter values. With AntTweakBar UI is added with a single line of code for any variable you want to expose. Moreover AntTweakBar figures out which type of UI element should show up: switches for bools, RGB/HSV value manipulators for colors, spinners for numbers. And it’s all Glut and OpenGL (and DirectX I guess), which for most is exactly what they’re already using.

Compiling and installing AntTweakBar as a dynamically linked library on a mac is a bit tricky though. Here’s what I did:

Dowload the source from the AntTweakBar site.

Go to the source directory:


cd AntTweakBar/src


I had to make some changes to the Makefile.osx. Edit the lines to look like this


CXXCFG          = -O3 -arch i386 -arch x86_64
LFLAGS          = -arch i386 -arch x86_64
OUT_DIR         = /usr/local/lib

BASE            = /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks

 

I want to compile AntTweakBar universally (32-bit and 64-bit) for a 10.6 machine so I need those -arch options. You can leave those out if you just want the default setting.

Copy Makefile.osx over the exisiting Makefile:


cp Makefile.osx Makefile


Then build with


sudo make


This will put the dylib in the right place so you don't have to mess with DYLD_LIBRARY_PATH each time you link to AntTweakBar

Since I've installed libAntTweakBar.dylib all the way at the /usr/local/ level, I'll also put the header file there:


sudo cp ../include/AntTweakBar.h /usr/local/include


Now, hop over to the examples directory:


cd ../examples


Now you should be able to universally compile a simple example with the following:


gcc -O3 -arch i386 -arch x86_64 -Wall -fno-strict-aliasing -D_MACOSX TwSimpleGLUT.c -lAntTweakBar -lpthread -lm -framework OpenGL -framework GLUT -o TwSimpleGLUT


And run it with:


./TwSimpleGLUT


And you should get something like this:

Update:
Mac ports does have a port for AntTweakBar, but it's always such a nightmare dealing with the 32-bit/64-bit problem with mac ports so I have done the above. With macports you can just issue:


sudo port install anttweakbar


And you should be able to compile and run the example in the same manner.

### Compiling L-BFGS-B on Mac OS X and mixing with c++

Tuesday, August 17th, 2010

A new optimization problem required a black box solver that could impose constant bounds on the variables. We opted to use an implementation of L-BFGS-B which does exactly that.
I’m working on a Mac OS X, 10.6, machine and our code base is in c++. So I needed to compile the L-BFGS-B code, which is in fortran and be able to call it from cpp files.

### Compiling L-BFGS-B

Note: the following solution requires that you have a proper f2c installed. I used these steps to compile a universal (32-bit and 64-bit) f2c.

You’ll notice there are four *.f files:
routines.f contains the solver
driver*.f contain examples showing you how to set up the parameters to the solver

The Makefile included in the source will try to compile all four files into *.o object files then make executables out of each example. When I try:


make


it seems that while the object files for each *.f file get created, my f77 doesn’t understand how to make the executables. I get errors like this:


f77 -O driver3.o routines.o -o x.lbfgsb3
invalid parameter driver3.o
Undefined symbols:
"_MAIN__", referenced from:
_main in libf2c.a(main.o)
collect2: ld returned 1 exit status


This would be OK because I don’t really care about the example executables. But in order to figure out how to call subroutines from routines.o from C/C++, I’ll need to know that they work in the first place. Moreover, f77 was creating x86_64 object files and my code base is i386 (though I’m trying my hardest to build the dependencies as universals).

After digging around in the F77 script I first found where I could tell the compiler to make universal binaries. I do that by setting the CFLAGS environment variable. So as a replacement for the faulty Makefile, I’ve composed this script which should do the same thing but make everything universal for the mac:

Save this in the same directory as the *.f files as make_all.sh:


#!/bin/bash

# save old CFLAGS value
OLD_CFLAGS=$CFLAGS; # set CFLAGS used by F77 to contain gcc parameters necessary to produce # universal object files export CFLAGS="$CFLAGS -arch i386 -arch x86_64";

# compile the algorithm as a universal object file
f77 -O -c -o routines.o routines.f

# compile each of the examples as universal executables
for i in 1 2 3
do
# translate driver*.f to driver*.c
f2c driver$i.f # compile driver*.c to universal binary driver*.o cc$CFLAGS -c -o driver$i.o driver$i.c
# link driver*.o and routines.o into unversal binary executable x.lbfgsb*
cc $CFLAGS driver$i.o routines.o -lf2c -lm -o x.lbfgsb$i # remove driver*.c rm driver$i.c
done

# restore old CFLAGS value
export CFLAGS='$OLD_CFLAGS';  Call it by issuing:  bash make_all.sh  You can test that everything went ok by executing ./x.lbfgsb1, ./x.lbfgsb2, ./x.lbfgsb3. ### Mixing with C++ Now that we have a universal routines.o, we would like to be able to call the algorithm subroutines from a c++ program. I could use f2c to “translate driver1.f” into c++, but all it does is translate it into c and put it in an extern "C" block. Instead I used f2c to translate driver1.f into c code, then methodically human-translated that into a (more) human-readable cpp program. Below is my human readable version of driver1.f. Save it in a file called driver1.cpp:  /* driver1.f -- translated by f2c (version 20090411). You must link the resulting object file with libf2c: on Microsoft Windows system, link with libf2c.lib; on Linux or Unix systems, link with .../path/to/libf2c.a -lm or, if you install libf2c.a in a standard place, with -lf2c -lm -- in that order, at the end of the command line, as in cc *.o -lf2c -lm Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., http://www.netlib.org/f2c/libf2c.zip */ // Compile this with // !c++ routines.o -lf2c -lm -o driver1cpp driver1.cpp #include "f2c.h" #include "stdio.h" /* DRIVER 1 */ /* -------------------------------------------------------------- */ /* SIMPLE DRIVER FOR L-BFGS-B (version 2.1) */ /* -------------------------------------------------------------- */ /* L-BFGS-B is a code for solving large nonlinear optimization */ /* problems with simple bounds on the variables. */ /* The code can also be used for unconstrained problems and is */ /* as efficient for these problems as the earlier limited memory */ /* code L-BFGS. */ /* This is the simplest driver in the package. It uses all the */ /* default settings of the code. */ /* References: */ /* [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, A limited */ /* memory algorithm for bound constrained optimization'', */ /* SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208. */ /* [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, L-BFGS-B: FORTRAN */ /* Subroutines for Large Scale Bound Constrained Optimization'' */ /* Tech. Report, NAM-11, EECS Department, Northwestern University, */ /* 1994. */ /* (Postscript files of these papers are available via anonymous */ /* ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.) */ /* * * * */ /* NEOS, November 1994. (Latest revision June 1996.) */ /* Optimization Technology Center. */ /* Argonne National Laboratory and Northwestern University. */ /* Written by */ /* Ciyou Zhu */ /* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */ /* NOTE: The user should adapt the subroutine 'timer' if 'etime' is */ /* not available on the system. An example for system */ /* AIX Version 3.2 is available at the end of this driver. */ // These are fortran wrappers and must be in C extern "C" { int setulb_(integer *, integer *, doublereal *, doublereal *, doublereal *, integer *, doublereal *, doublereal *, doublereal *, doublereal *, doublereal *, integer *, char *, integer *, char *, logical *, integer *, doublereal *, ftnlen, ftnlen); /* Builtin functions */ integer s_wsfe(cilist *), e_wsfe(void); /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen); integer s_cmp(char *, char *, ftnlen, ftnlen); /* Subroutine */ int s_stop(char *, ftnlen); } /* ************** */ /* Main program */ int main(void) { /* Local variables */ doublereal f, g[1024]; doublereal l[1024]; integer m, n; doublereal u[1024], x[1024], t1, t2, wa[42584]; integer nbd[1024], iwa[3072]; char task[60]; doublereal factr; char csave[60]; doublereal dsave[29]; integer isave[44]; logical lsave[4]; doublereal pgtol; integer iprint; /* This simple driver demonstrates how to call the L-BFGS-B code to */ /* solve a sample problem (the extended Rosenbrock function */ /* subject to bounds on the variables). The dimension n of this */ /* problem is variable. */ /* nmax is the dimension of the largest problem to be solved. */ /* mmax is the maximum number of limited memory corrections. */ /* Declare the variables needed by the code. */ /* A description of all these variables is given at the end of */ /* the driver. */ /* Declare a few additional variables for this sample problem. */ /* We wish to have output at every iteration. */ iprint = 1; /* We specify the tolerances in the stopping criteria. */ factr = 1e7; pgtol = 1e-5; /* We specify the dimension n of the sample problem and the number */ /* m of limited memory corrections stored. (n and m should not */ /* exceed the limits nmax and mmax respectively.) */ n = 25; m = 5; /* We now provide nbd which defines the bounds on the variables: */ /* l specifies the lower bounds, */ /* u specifies the upper bounds. */ /* First set bounds on the odd-numbered variables. */ for(int i = 0; i < n; i+=2){ nbd[i] = 2; l[i] = 1.; u[i] = 100.; } /* Next set bounds on the even-numbered variables. */ for(int i = 1; i < n; i+=2){ nbd[i] = 2; l[i] = -100.; u[i] = 100.; } /* We now define the starting point. */ for(int i = 1; i < n; i++){ x[i] = 3.; } printf(" Solving sample problem.\n"); printf("f = 0.0 at the optimal solution.)\n"); /* We start the iteration by initializing task. */ s_copy(task, "START", (ftnlen)60, (ftnlen)5); /* ------- the beginning of the loop ---------- */ while(true){ /* This is the call to the L-BFGS-B code. */ setulb_(&n, &m, x, l, u, nbd, &f, g, &factr, &pgtol, wa, iwa, task, & iprint, csave, lsave, isave, dsave, (ftnlen)60, (ftnlen)60); if (s_cmp(task, "FG", (ftnlen)2, (ftnlen)2) == 0) { /* the minimization routine has returned to request the */ /* function f and gradient g values at the current x. */ /* Compute function value f for the sample problem. */ f = .25*(x[0]-1.)*(x[0]-1.); for(int i = 1;i<n;i++){ f += (x[i] - x[i-1]*x[i-1])*(x[i] - x[i-1]*x[i-1]); } f *= 4.; /* Compute gradient g for the sample problem. */ t1 = x[1] - x[0]*x[0]; g[0] = (x[0] - 1.) * 2. - x[0] * 16. * t1; for(int i = 1;i<n-1;i++){ t2 = t1; t1=x[i+1]-x[i]*x[i]; g[i] = 8.0*t2-16.*x[i]*t1; } g[n - 1] = t1 * 8.; /* go back to the minimization routine. */ }else if (s_cmp(task, "NEW_X", (ftnlen)5, (ftnlen)5) == 0) { /* the minimization routine has returned with a new iterate, */ /* and we have opted to continue the iteration. */ }else{ // anything other than "FG" or "NEW_X" means termination /* If task is neither FG nor NEW_X we terminate execution. */ break; } } return 0; }  Note: You’ll get runtime errors if you find/replace all of the “integer” keywords with “int”. I guess these are defined by f2c.h. All I know is, leave them alone. Compile this with:  c++ -arch x86_64 -arch i386 routines.o -lf2c -lm -o driver1cpp driver1.cpp  And you should be able to execute your cpp program with  ./driver1cpp  ### Compiling L-BFGS-B nonlinear optimizer for mac os x Monday, August 16th, 2010 Just running:  make  on the fortran source code of L-BFGS-B gave me linker errors on my mac OS X 10.6 machine:  invalid parameter driver1.o Undefined symbols: "_s_wsle", referenced from: _subsm_ in routines.o ....  I fixed this by installing g77, following these instructions. Then changed the value of F77 in the makefile of L-BFGS-B:  #FC = f77 FC = g77  Then running  make  produced i386 executables and object files. Note: I’m not sure what you would need to change to produce x86_64 files, luckily for me I wanted i386 all along. Update: So the examples that g77 creates above work fine. But when I tried to call the fortran subroutines from c or cpp code I got weird errors. To solve this I switched gears and opted to use f2c/f77 and universal binaries, this so far is working much better. ### taucs on Mac OS X Tuesday, July 13th, 2010 Yesterday I spent way too long trying to get taucs compiled and linking on a Mac machine running OS X 10.6. Because my Qt is compiling for 32 bits I needed a 32-bit/i386 libtaucs.a, this was not so easy. I began hoping to compile a universal library, but couldn’t manage to do it. I’ve previously posted about how to compile a 64-bit version of taucs on a mac 10.6 machine (this was not so bad). Update: Thanks to the useful comment below, I’ve modify these steps so that the result is a unviersal (32-bit and 64-bit) libtaucs.a ### Part one: Compiling libtaucs.a (universal) In the taucs directory (here on out [taucs] issue the following:  cp config/darwin.mk config/darwin10.0.mk  Then open up config/darwin10.0.mk and edit the following lines to look like this:  CFLAGS = -arch i386 -arch x86_64 -O3 -faltivec   LIBBLAS = -framework Accelerate LIBLAPACK = -framework Accelerate LIBMETIS = -lmetis   LIBF77 = -lf2c  Now, this part is really messy but hopefully I’ll remember everything I did. Before compiling libtaucs.a we need to compile libf2c.a and libmetis.a, and we need to do it so that both are at least i386. I think I managed to get mine to both be universal (i386 and x86_64). So, I’ve stripped these commands out of the buildf2c.sh script. Issue them in a terminal:  curl http://netlib.sandia.gov/cgi-bin/netlib/netlibfiles.tar?filename=netlib/f2c -o "f2c.tar" tar -xvf f2c.tar gunzip -rf f2c/* cd f2c unzip libf2c.zip -d libf2c cd .. sed 's/CC = cc/CC = \/usr\/bin\/cc/' f2c/libf2c/makefile.u > f2c/libf2c/makefile sed 's/CC = cc/CC = \/usr\/bin\/cc/' f2c/src/makefile.u > f2c/src/makefile  At this point we need to edit the makefiles to make sure that they build universal libraries: In libf2c/makefile edit the following lines to look like this:  CFLAGS = -arch x86_64 -arch i386 -O LDFLAGS += -arch x86_64 -arch i386 # compile, then strip unnecessary symbols .c.o:$(CC) -c -DSkip_f2c_Undefs $(CFLAGS)$*.c
#        ld $(LDFLAGS) -r -x -o$*.xxx $*.o # mv$*.xxx $*.o  AND AGAIN in src/makefile edit the following lines to look like this:  CFLAGS = -arch x86_64 -arch i386 -O LDFLAGS += -arch x86_64 -arch i386 # compile, then strip unnecessary symbols .c.o:$(CC) -c -DSkip_f2c_Undefs $(CFLAGS)$*.c
#        ld $(LDFLAGS) -r -x -o$*.xxx $*.o # mv$*.xxx \$*.o


Note: Be sure to comment out the ld ... and mv ... lines above.

Now back to compiling:


cd f2c/libf2c
make f2c.h
if test ! -d /usr/local/include; then
sudo mkdir -p /usr/local/include
fi
sudo cp f2c.h /usr/local/include/
make
if test ! -d /usr/local/lib; then
sudo mkdir -p /usr/local/lib
fi
sudo cp libf2c.a /usr/local/lib/
sudo ranlib /usr/local/lib/libf2c.a
cd ../src
make
if test ! -d /usr/local/bin; then
sudo mkdir -p /usr/local/bin
fi
sudo cp f2c /usr/local/bin/
cd ..
chmod +x fc
sudo cp fc /usr/local/bin
sudo ln  -s /usr/local/bin/fc /usr/local/bin/f77
sudo chmod +x /usr/local/bin/f77


Following the rest of the buildf2c.sh on your own to build the executables.

Next, we need to compile libmetis.a.

Download and unzip the source then in the metis folder edit Makefile.in:


# What options to be used by the compiler
COPTIONS = -arch i386 -arch x86_64

# What options to be used by the loader
LDOPTIONS = -arch i386 -arch x86_64


Then issue:


make


and then


sudo cp libmetis.a /usr/local/lib/


Now, finally, go back to [taucs]. Here you can issue:


./configure
make


This should produce a universal libtaucs.a library.

### Part two: Using libtaucs.a

You should have no problem compiling any of the examples, like those in [taucs]/progs, as long as you include the right headers and the library. For example I can issue the following (be sure to replace the [taucs]s):


cc -arch i386 -o direct [taucs]/progs/direct.c \
-I[taucs]/src/ -I[taucs]/build/darwin10.0/ \
-L[taucs]/lib/darwin10.0/ -ltaucs -framework \
Accelerate -lmetis -lf2c


or


cc -arch x86_64 -o direct [taucs]/progs/direct.c \
-I[taucs]/src/ -I[taucs]/build/darwin10.0/ \
-L[taucs]/lib/darwin10.0/ -ltaucs -framework \
Accelerate -lmetis -lf2c


Though I do get the warning:


In file included from taucs_with_LU/src/taucs.h:7,
from taucs_with_LU/progs/direct.c:17:
taucs_with_LU/build/darwin10.0/taucs_config_build.h:5:24: warning: missing whitespace after the macro name


This is because of a #define that uses darwin10.0 and periods are not allowed.

Update:

If you are using a mac then taucs will try to define a macro called OSTYPE and set it to an invalid c value: darwin10.0 (invalid because of the period). As a result whenever you include taucs.h you’ll get hundreds of warnings. I fix this by opening [taucs]/build/taucs_config_build.h and commenting out the following lines before I make:


/* This is an automatically generated file */
/* Configuration name: anonymous */
//#define TAUCS_OSTYPE darwin10.0
...
//#define OSTYPE_darwin10.0
...


You should also be able to compile this simple c program, saved in taucs_super_simple.c:


#include <taucs.h>
int main(int argc, char* argv[])
{
double x = taucs_get_nan();
return 1;
}


I can compile and run this with:


cc -arch i386 -o taucs_super_simple taucs_super_simple.c \
-I[taucs]/src/ -I[taucs]/build/darwin10.0/ \
-L[taucs]/lib/darwin10.0/ -ltaucs -framework Accelerate
./taucs_super_simple


Now if you try the same simple program, naively translated to cpp like this, saved in taucs_super_simple.cpp:


extern "C"{
#include <taucs.h>
}
int main(int argc, char* argv[])
{
double x = taucs_get_nan();
return 1;
}


and you try to compile with something like this:


c++ -arch i386 -o taucs_super_simple taucs_super_simple.cpp \
-I[taucs]/src/ -I[taucs]/build/darwin10.0/ \
-L[taucs]/lib/darwin10.0/ -ltaucs -framework Accelerate


You’ll get a bagillion of these errors:


/usr/include/c++/4.2.1/complex:1104: error: template with C linkage


That’s because taucs.h uses some complex library that is weird. Not sure why exactly you have to do this, but just add:


#include <complex>


above

extern "C"{
#include <taucs.h>
}

Do this anytime you include taucs. This should now compile with the above command.

### Compiling libtaucs.a for Mac OS X 10.6

Monday, July 12th, 2010

This was my second attempt at compiling taucs for a mac. After some frustrating compiling and recompiling, I think I’ve figured out how to do it.

In the taucs directory:


cp config/darwin.mk config/darwin10.0.mk


Then edit the following lines in config/darwin10.0.mk to look like this:


LIBBLAS   = -framework Accelerate
LIBLAPACK = -framework Accelerate


Remove the libf2c.a file if it came with your taucs distribution:


rm external/lib/libf2c.a


Download the metis source and build it. For me this just meant issuing make.

Then copy the libmetis.a file from the metis directory to the taucs directory (change paths accordingly):


cp metis-4.0/libmetis.a taucs/external/lib/libmetis.a


Finally in the taucs directory you can configure and make:


./configure
make


Update: The above solution produces a 64-bit, x86_64 library on a 10.6 mac machine. Unfortunately I need a 32-bit, i386 library (or universal) because Qt still defaults to 32-bits.