Wednesday, February 20, 2013

Building lp_solve on Visual Studio 2010

This took me quite some time to figure out the most straightforward way to do it, but I finally did thanks to this. It reported that lp_solve.5.5 has memory leaks and therefore recommends lp_solve.5.1, but 5.1 was no longer available for Windows download on their sourceforge site. It's not safe to assume, but there've been several 5.5.* versions, and many people using 5.5.2, so I guess 5.5.2 works for most people.

1. Create a main.cpp (can be empty) in a new folder, e.g. lpsolveFiles. Paste all the header files unzipped from lp_solve_5.5.2.0_dev_win32 (would be win64 if you're making a 64-bit Visual Studio project, not if your machine is 64-bit).
2. Open Visual Studio 2010 > New > Project from Existing Code
3. Select project folder to be where you want to place your project (this is the project directory), give it a name, and "Add files from these folders", choose lpsolveFiles. Click Next.
4. Select Visual Studio, create as Console Application. Click Finish.
5. Now, copy and paste lpsolve55.lib and lpsolve55.dll from lp_solve_5.5.2.0_dev_win32 to project directory.
6. In Visual Studio 2010, select your project, then click Project > Properties > Configuration Properties > Linker > Input. In Additional dependencies, add "lpsolve55.lib;".
7. In main.cpp, copy and paste the sample code from Statically Link ... > Implicit Linking ... on http://lpsolve.sourceforge.net/5.5/Build.htm
8. Now you should be able to build with F7.

If you get external symbols not resolved, you may be using a 32-bit (if it's 64-bit), or vice versa.
If you get other link errors, you may have copied the wrong library (e.g. liblpsolve55.lib instead of lpsolve55.lib)