Diego’s CS research blog

July 10, 2008

Using lp_solve in Java with Mac OS X

Filed under: Uncategorized — Diego @ 3:27 pm

Sometimes research (at least in my case) means to spend (a lot of) time to configure some application, in this case lp_solve a linear programming solver written in C.

As it often happens there were not so many informations on how to use lp_solve in Java in Mac OS X, the reason is that not a lot of people try to do it in MAC OS X…

If you do it in Windows it is really easy, in Unix you just follow the instructions, but in the Java wrapper the instructions to set up everything (lp_solve + lp_solve Java wrapper) in MAC OS X are WRONG (or incomplete)!

So if you have a mac and want to use lp_solve in your java applications, this post is for you!

After a day of browsing I found in a mailing list a step-by-step guide at this URL: http://osdir.com/ml/mathematics.lpsolve/2006-02/msg00189.html
Thanks to John Gleeson who wrote it.

This is the guide (a mirror in this blog for this guide is always helpful!):

How to build and install the lp_solve Java extension on Mac OS X:

Download and expanded lp_solve_5.5_source.tar.gz into a
directory named 'lp_solve_5.5'.

Download and expand lp_solve_5.5_java.zip into a
directory named 'lp_solve_5.5_java'.

1) Build the lp_solve library.

$ cd lp_solve_5.5/lpsolve55
$ sh ccc.osx

This creates two new files in the lpsolve55 subdirectory:

$ ls liblp*
liblpsolve55.a     liblpsolve55.dylib

2) Install the lp_solve library.

If not already in directory lpsolve55, cd to it.  Copy liblpsolve55.a
and
liblpsolve55.dylib to /usr/local/lib (you may need to create
/usr/local/lib first: sudo mkdir -p /usr/local/lib):

$ sudo cp liblpsolve55.a liblpsolve55.dylib /usr/local/lib

3) Test the build and installation.

$ cd lp_solve_5.5/demo

The ccc.osx script is broken.  The good news is that version 5.5 of
lp_solve fixes the "malloc.h" incompatibility on the Mac that was in
earlier versions.  The Unix/Linux script now works on OS X.  Be
patient...
it may take several seconds to build 'demo':

$ sh ccc

The example problems in the demo should issue no errors and have
"Excellent numeric accuracy ||*|| = 0":

$ ./demo

4) Build the lp_solve JNI extension.

$ cd lp_solve_5.5_java/lib/mac

The script "build-osx" in the mac subdirectory is a DOS text file:

$ file build-osx
build-osx: ASCII English text, with CRLF line terminators

If you try execute this file, you will get "command not found"
errors.  To
convert it into a Unix file, remove the carriage returns:

$ tr -d "\r" < build-osx > build-osx1

Edit build-osx1 to set LPSOLVE_DIR to the location of directory
lp_solve_5.5 on your computer. Change the two occurrences of '5.1' to
'5.5' and the two occurrences of '51' to '55' in the last line of
build-osx1.

$ sh build-osx1

This creates the extension library liblpsolve55j.jnilib.

5) Install  the lp_solve JNI extension.

The file liblpsolve55j.jnilib should be copied to /Library/Java/
Extensions
if you want it to be available to all users.  We assume this will be a
private installation (create the Java extensions directory if necessary;
e.g., mkdir -p ~/Library/Java/Extensions):

$ cp liblpsolve55j.jnilib ~/Library/Java/Extensions

6) Test the Java extension:

$ cd lp_solve_5.5_java/demo
$ java -cp ./demo.jar:../lib/lpsolve55j.jar Demo

The numerical results of the Java Demo should be identical to those
of the
C demo.

There is a Java unit test.  Out of 122 tests, I got 5 errors and 3
failures, all of which could be explained (missing XLI applications,
missing BFP libraries, outdated version numbers in tests, negligible
floating point differrences):

$ java -cp ./unittests.jar:../lib/lpsolve55j.jar:../lib/junit.jar
LpSolveTest

7) For more information about Java programming on Mac OS X:

Java Frequently Asked Questions: Common Development Questions
<http://developer.apple.com/java/faq/development.html>
Advertisements

19 Comments »

  1. Thanks for the instructions. By following them, I managed to get the demo to work from
    the terminal. However, I need to use lpsolve in an Eclipse project. I was
    wondering if you could give any advice on using the resulting
    lpsolve55j.jar with Eclipse. Any help would be greatly appreciated.
    Thanks for the blog post by the way.

    Comment by C. Staudt — January 27, 2009 @ 2:35 pm | Reply

  2. Once you have installed the library, you just need to use the java wrapper. That is you need to include the jar file in your project: go on “properties” of your project then select “Libraries” and click on “add external jar”.
    (I usually keep a folder in the workspace named “myLib” where I keep my jars which I need to include in my projects)

    Hope this helps!
    Good luck.
    – Diego

    Comment by Diego — January 27, 2009 @ 2:52 pm | Reply

  3. Got these instructions to work on OS X with 64-bit Java6. Just follow these instructions, but add -arch x86_64 to all the c$ and g++ commands in ccc.osx and build-osx1.

    Comment by Schmo — August 4, 2009 @ 3:26 pm | Reply

    • Hi. I couldn’t make it work for jdk 6 with 64bit OSX.
      I added “-arch x86_64” after all “$c” in ccc.osx. But I couldn’t even run ccc.osx with sh. It gives errors like:
      cc1: error: unrecognized command line option “-Wno-long-double”
      ….
      libtool: can’t open file: lp_MDO.o (No such file or directory)
      ….

      Comment by Naushad — March 2, 2010 @ 2:46 am | Reply

      • To get around the no-long-double problem replace the ‘c=cc’ line with ‘c=gcc-4.0’

        Comment by Ethan — June 29, 2010 @ 6:35 pm

  4. If anyone just need the libraries for 64 bit Mac and JDK 6 (and unable to make it work), I found the libraries at:

    http://www.soc.tuwien.ac.at/trac/jop/browser/liblpsolve55j.jnilib

    http://www.soc.tuwien.ac.at/trac/jop/browser/liblpsolve55.dylib

    Comment by Naushad — March 2, 2010 @ 3:17 am | Reply

  5. Ok, so here is a put-it-all-together summary, for what you need and what you do to get lpsolve working on Mac OS X 10.6 with Java 6, all in three simple steps:

    1) Get the two pre-compiled files liblpsolve55j.jnilib and liblpsolve55.dylib from links mentioned above.

    2) Copy liblpsolve55j.jnilib to ~/Library/Java/Extensions and liblpsolve55.dylib to /usr/local/lib and chmod to executable.

    3) Set your DYLD_LIBRARY_PATH to /usr/local/lib

    Thant’s it! No compiling required, no other files required. Happy lpsolving!

    Comment by Edward — February 20, 2011 @ 12:32 am | Reply

  6. I have lp_solve running native on IPAD and IPHONE.

    Comment by Tom — April 21, 2011 @ 10:08 am | Reply

  7. hi you said it is easily to use lpsolve with windows well i have windows xp and i’m programming an appliction with java netbeans but i stil don’t know how to link java with lpsolve could you learn me how to do for that??
    i’ve installed the lpsolve programm but i don’t know what i need else.
    ca u give me some advices insruction to follow pleaaaaaze help

    Comment by sisiim — June 16, 2011 @ 2:04 pm | Reply

    • Hi this is the best link I can provide you with. http://lpsolve.sourceforge.net/

      It should be well explained by the docs there how to install and use lpsolve with Java under windows xp.

      Hope this helps. – Diego

      Comment by Diego — June 16, 2011 @ 2:25 pm | Reply

  8. Woah! I’m really digging the template/theme of this blog. It’s simple, yet effective.
    A lot of times it’s difficult to get that “perfect balance” between superb usability and visual appearance. I must say that you’ve done a amazing job with this.
    Also, the blog loads extremely quick for me on Chrome.
    Exceptional Blog!

    Comment by Phen375 Reality — May 2, 2013 @ 7:37 pm | Reply

  9. Great work! This is the type of info that are supposed to
    be shared around the net. Shame on Google for
    now not positioning this put up upper! Come on over and talk over with my web site .

    Thank you =)

    Comment by www.qq-xiyou.info — May 26, 2013 @ 4:22 am | Reply

  10. Hello, I’ve been trying to add the required libraries for Lpsolve on a 64 bit Mac but I get a 404 error using this URL: http://www-sop.inria.fr/members/Jean-Vivien.Millo/kpassa/lpsolve_lib_mac64.zip Can anyone point me to a good URL?

    Thank You

    Comment by Zaid — November 7, 2013 @ 10:30 am | Reply

  11. Howdy! I could have sworn I’ve been to your blog before but after browsing through many of the posts
    I realized it’s new to me. Anyways, I’m definitely delighted I came across it
    and I’ll be book-marking it and checking back regularly!

    Comment by speed up mac — November 9, 2013 @ 5:45 am | Reply

  12. In case it helps anyone, when I run “$ sh ccc.osx” on OSX 64-bit, the files “liblpsolve55.a” and “liblpsolve55.dylib” are created in a subdirectory bin/osx64/. During running the script I got several warning messages. But i guess that is normal.

    Comment by xa4 — May 1, 2014 @ 11:01 am | Reply

  13. […] tried the instructions here, gives […]

    Pingback by using lp_solve in java with mac, no lpsolve55j in java.library.path — August 28, 2014 @ 9:44 am | Reply

  14. Hi all!

    I have just put all required files in order to make lp_solve run on my El Captain Mac OS with Java 1.6. No need to download anything else!!!

    I did it and had OSDEA running perfectly.

    Download and unzip http://www.xilya.com.br/lp_solve-libs-for-mac-64-java-1.6.zip

    Now, as Edward wrote earlier, just copy liblpsolve55j.jnilib to /Library/Java/Extensions and liblpsolve55.dylib and liblpsolve55.dylib to /usr/local/lib. Then chmod to executable all three of them. After that, set your DYLD_LIBRARY_PATH to /usr/local/lib by adding the following to the last line of your .bash_profile:

    export DYLD_LIBRARY_PATH=/usr/local/lib:$DYLD_LIBRARY_PATH

    Happy lp_solving!

    Comment by Marcelo C. Fernandes (@MCarvalhoF) — March 28, 2016 @ 12:31 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: