lp_solve lpsolve java MAC osx

2017-05-01 20:51:38来源:CSDN作者:huntstart人点击

经过众多尝试,lp_solve是开源代码中最好用的具有整数线性规划能力的工具,易学简单还免费,支持各种不同的语言。
我的gcc 版本是4.2,java版本是1.8。

这篇文章内容总体还可以,但是需要更新!具体请点击本行字。下面是我的操作过程。

  1. 下载lp_solve_5.5_source.tar.gz和lp_solve_5.5_java.zip并解压为lp_solve_5.5和lp_solve_5.5_java
  2. cd lp_solve_5.5/lpsolve55
  3. sh ccc.osx
  4. bin/osx64/中生成了liblpsolve55.a和liblpsolve55.dylib,拷贝他们到lp_solve_5.5/lpsolve55
  5. lp_solve_5.5_java/lib/mac中的build-osx修改为如下形式
# -------------------------------------------------------------------# This is a build file for the lp_solve Java wrapper stub library# on Mac OS X platforms.## Requirements and preconditions:## - gcc and g++ compiler installed (I used gcc Version 3.3 20030304 )# - Apple JDK 1.4 installed (I have JDK 1.4.2)# - lp_solve archive (lp_solve_5.5_source.tar.gz) unpacked## Change the paths below this line and you should be ready to go!# -------------------------------------------------------------------LPSOLVE_DIR=/xxxxxxxxx/lp_install_files/lp_solve_5.5/JDK_DIR=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers# OK, here we go!SRC_DIR=../../src/cINCL="-I $JDK_DIR -I $LPSOLVE_DIR -I $SRC_DIR -idirafter /usr/include/sys"g++ -fPIC -fno-common $INCL -c $SRC_DIR/lpsolve5j.cppg++ -dynamiclib lpsolve5j.o -compatibility_version 5.5.0 -current_version 5.5.0 -o liblpsolve55j.jnilib -lc /xxxxxxxxxxxxxx/lp_solve_5.5/liblpsolve55.a

其中JDK_DIR可以用find / -name "jni_md.h" 来找,会出来好几个包含jni_md.h的目录,挨个试试。

  1. sh build-osx,一切顺利的话会得到一个liblpsolve55j.jnilib。
  2. 最后把liblpsolve55.a,liblpsolve55.dylib, liblpsolve55j.jnilib, lpsolve55j.jar放到java的lib路径中,可以通过下面的代码动态添加用户的lib文件夹:
CLASSPATH=$CLASSPATH:$JNEAT_LOCATION'/xxxx/lpsolver-mac64'CLASSPATH=$CLASSPATH:$JNEAT_LOCATION'/xxxx/lpsolver-mac64/lpsolve55j.jar'export CLASSPATHexport LD_LIBRARY_PATH=$JNEAT_LOCATION'/xxxx/lpsolver-mac64'javac Demo.javajava -Djava.library.path=./xxxx/lpsolver-mac64 Demo

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台