lp_solve 线性规划求解包的使用

来源:互联网 发布:淘宝66活动 编辑:程序博客网 时间:2024/06/07 22:22

网上关于lpsolve的资料不多,也没有怎么说配置,对于初入这个包的人来说,非常痛苦,我也是搞了一天,才在mac和win上都搞了出来。具体使用还是蛮简单的。

内容post在了stack overflow上,本来是个提问帖,结果自问自答了。这是链接:https://stackoverflow.com/questions/46639534/using-lp-solve-with-visual-studio-2015。 原文也搬过来了,懒得翻译了。



0down votefavorite

I'm rather new to C++. I'm trying to use VS2015 and the lp_solve library(https://sourceforge.net/projects/lpsolve/files/lpsolve/5.5.2.5/) to solve my linear eq problem(for exact Gromov-Hausdorrf Distance, see https://mediatum.ub.tum.de/doc/1231885/1231885.pdf section 3.1 and 3.3). My machine is x64 system. Here is what I've done:

  • donwload the lp_solve_5.5.2.5_dev_win64.zip package and decompress it.
  • specific the library directoy(through project -> properties -> linker)
  • specific lib I used (liblpsolve55.lib and liblpsolve55d.lib for statically linking) through project->properties->linker->input->additional dependency.
  • declare the .h file directory(through project->properties->C/C++).
  • Here is what I declare in my code:

    #include "lp_lib.h"

    #pragma comment(lib, "liblpsolve55.lib") // static

    #pragma comment(lib, "liblpsolve55d.lib") // static for debug

While when I run the code with x86, it will show the following problems:

  • error LNK2019: unresolved external symbol _make_lp@8 referenced in function "void __cdecl my_solve [totally 13 errors like this]
  • warning LNK4272: library machine type 'X86' conflicts with target machine type 'x64' [totally 2 warnings like this]

While when I switch the runner with x64:

  • I got 550 errors, mainly due to the “dlfcn.h”: No such file or directory
  • in the lp_lib.h file, it has lines:

    #if (LoadInverseLib == TRUE) || (LoadLanguageLib == TRUE)  #ifdef WIN32    #include <windows.h>  #else    #include <dlfcn.h>  #endif#endif
  • which means it has treat me as a linux machine since dlfcn.h is for unix/linux

I've also try to use the 32bit version package(lp_solve_5.5.2.5_dev_win32.zip), but it do not work either.

  • with x86 runner:__iob, _printf issues.
  • with x64 runner:“dlfcn.h”: No such file or directory

I've successively build and run the demo in my mac with the corresponding package(lp_solve_5.5.2.5_dev_osx32.tar.gz). But I still want to know how to build and run it in VS2015.

Here I'll state what I do in mac if anyone need it(using Xcode).

  • download the lp_solve_5.5.2.5_dev_osx32.tar.gz package
  • add all the .h file in build phase -> headers
  • add the liblpsolve55.a file in build phase -> link binary with libraries
  • (if you want to use .dylib as dynamic linking, add it to the build phase -> copy file, but it do not work for me)
  • in build setting, set the Architectures to 32-bit intel
  • in build setting, set the Build Active Architecture Only to No

Thank you very much, actually nobody answer this question :) But I've solve the problem myself. Here is what I do for VS2015:

  • use package lp_solve_5.5.2.5_dev_win32.zip

  • add the .h file and .lib as above

  • change the run library, through properties -> C/C++ -> code generation -> run library -> change the DLL(/MDd) to (/MTd)

  • if you still got some fprintf issues, go to properties -> linker -> input -> additional dependency, and add : legacy_stdio_definitions.lib

That will be OK. That my be some translation issue, yes I use the chinese-version VS...

原创粉丝点击