PDA

View Full Version : How to integrate lp solver to QT



cancelik
28th April 2016, 20:10
Hello,

I am very new to QT and also have basic knowledge of programming. I should create an simple interface and I should also use a linear solver, so I found glpk as a free software, which can be also integrated to QT. I have loaded the package and could use the solver in Visual Studio but when I tried for QT I failed. I did the instructions on this website: first I have completed these steps https://en.wikibooks.org/wiki/GLPK/Windows and got optimal solution found. After that for compiling on QT https://en.wikibooks.org/wiki/GLPK/Compiling_with_the_GLPK_library but at the end I get error message undefined reference to 'glp_version' I am pretty sure that I have written the correct path. Any idea what I am doing wrong?
Thank you

d_stranz
28th April 2016, 20:53
You changed the LIBS and INCLUDEPATH variables in your .pro file to point to where you have GLPK installed if it isn't in the same place as shown on the wiki page, right?

You are using the MSVC compiler as your kit in Qt Creator, right? If you are using mingw in Qt Creator, and your GLPK library was built with Visual Studio, it will not link and you will get undefined reference errors.

If you are using the MSVC compiler in Qt Creator, are you using the same version of the compiler that was used to build your GLPK library?

Are you trying to link a Debug mode program to Release mode libraries (or vice versa)?

If you have been able to get this to work in Visual Studio, then getting it to work in Qt Creator is a matter of configuring the "kit" you are using for the project to point to the MSVC compilers and making sure you build and link in the same mode as the library (debug or release).

cancelik
28th April 2016, 23:16
I am sorry I am very newbie so please excuse if I say something stupid. I am using as kit MinGW, I just did what was written on https://en.wikibooks.org/wiki/GLPK/Windows until OPTIMAL SOLUTION FOUND. Is this what you mean as building? I dont know what was used for building? LIBS and INCLUDEPATH variables are correct I checked twice. I am very newbie I just have done steps in these two urls.

Added after 15 minutes:

I tried with MSVC compiler and got this error message: Error while building/deploying project glpknolur (kit: Desktop Qt 5.3 MSVC2013 OpenGL 64bit)
When executing step "Make"

Added after 46 minutes:

I have built GLPK library with VC 10 but this QT has MSVC13 as compiler, i think i should use some MSVC10 compiler, how can i add it to my QT?

Added after 54 minutes:

I have uninstalled my QT and downloaded Qt 5.2.1 because that one uses MSVC2010 but now I got the error LNK2019: unresolved external symbol _glp_version referenced in function _main. My system is 64bit but my kit is Desktop QT 5.2.1 MSVC 2010 32bit OpenGL. I downloaded qt-opensource-windows-x86-msvc2012-5.2.1.exe under https://download.qt.io/archive/qt/5.2/5.2.1/ . Do you have any idea which one should I download or is it any other problem?

d_stranz
29th April 2016, 03:30
Don't keep trying random things and hope that something will work. You need to follow some logic.

1 - Do you have the source code for your glpk library?
1a - If yes, then you can probably rebuild it using whatever compiler you choose - mingw or some flavor of MSVC. Pick one and use it.
1b - If no, then you need to match the compiler for your project to the one that was used to build the library.

2 - If you can build (or have) the library for a Visual Studio version, use Visual Studio for your Qt projects since you already seem to be familiar with it.
2a - Install the Qt version that matches your version of Visual Studio. Install the Qt Add-in for Visual Studio next.
2b - Configure the Qt Add-in to add your Qt version - select QT5 -> Options. If your Qt version isn't already listed, click Add to browse for it and add it.
2c - Set the default Qt version if needed.

3 - Create a new Qt project using the File -> New Project -> Qt5 Projects -> Qt Console Application

4 - Now you are going to have to look at the BAT files that you used when you followed the Wiki, and add the .cpp / .c and .h files that are probably listed there into the directory where you are going to build your Qt project. Copy them into the directory, then add them to the Qt project you just created. (In the VS Solution Explorer, right click on the project name and choose "Add -> Existing Item". Select the files you copied into the project directory.

5 - You will also need to tell Visual Studio to link to your library. In Solution Explorer, right-click on your project, select Properties, select Linker in the dialog, click Input, then click in the right side of Additional Dependencies. Browse for your library. Be sure to select the correct version - Debug or Release depending on which Configuration is shown as "Active" in this properties dialog.

Now you should be able to build the project. If it is a console project, it will probably flash up and disappear too quickly so open a Command Prompt window and run it from there.

cancelik
29th April 2016, 08:55
Thank you for your answer, the problem is they suggest to build this library with Visual Studio 2010, which I do. So I need a QT which uses MSVC2010 as compiler kit. I have looked into archives but couldn't find any with MSVC2010 for 64 bit. They were all 32 bit.

d_stranz
29th April 2016, 16:40
If you have the source code, you can rebuild the library with whatever version of MSVC you want. You do not have to use VS 2010. If you have a later version of MSVC (probably even an "Express" free version will work), then get the Qt distribution that has been pre-built for it. You don't have enough experience to build Qt from source code for Visual Studio 2010. You also do not need a 64-bit version of MSVC or Qt - the instructions on the GLPK page use a 64-bit compiler as an example only; they also mention 32-bit compilers.

Changing the .BAT file to use a different MSVC compiler just means changing the line that points to it:


set HOME="C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC"

On my PC, I have "Microsoft Visual Studio 9.0", "Microsoft Visual Studio 11.0", "Microsoft Visual Studio 12.0", and "Microsoft Visual Studio 14.0", so I could use any one of them just by changing "10" in the line above.