Installing SorpSim

Prerequisites

First determine your goals. To merely use the program, you need only download the installer and PDF manual, both available from the GitHub landing page.

However, if you wish to develop source code (fix bugs or add features), you will need the following. Note that the larger programs may take 10-20 minutes to install/compile.

  1. A C++ compiler compatible with all the libraries below
    • I find that VisualStudio 2017 Community Edition is satisfactory, albeit not open source. It is free but will require you to create a free account after 30 days. You also should install the command line debugger (CDB) from the Windows Driver Kit, but that is not required to compile and run code that already works. Also, for some reason I have also installed the Windows 10 SDK, but can't remember why.
    • You might also try GCC (or its Windows ports, MinGW and MSYS), since the program uses Qt and should thus be cross-platform.
  2. Qt
    • The usual installer should give you the Qt libraries and also an option to install QtCreator, an IDE that you should utilize. It includes the Qt documentation, tutorials, examples, and most importantly makes it relatively painless to manage a project, edit graphical user interfaces, and compile source using Qt.
    • If needed, after installing, optionally set up the debugger per http://doc.qt.io/qtcreator/creator-debugger-engines.html.
  3. Qwt library. Click through to http://sourceforge.net/projects/qwt/files. Download and extract to a local folder such as C:\qwt-6.1.3\. Then, read the project documentation (online or in the local doc folder) regarding installing. You will have to compile a shared library with your favorite compiler (eg. VisualStudio will give you a DLL file, MinGW will give you something).
  4. Git and optional remote repository
    • Git is used to track your changes to source code (in order to debug, share, and backup your work). You can find a standalone program to install, or get it via your favorite package manager (such as with Linux, or with Anaconda), or get it via GitHub desktop (see next bullet).
    • For the remote repository, consider opening an account with GitHub, since this platform makes it easy to communicate and synchronize with other teams already working on SorpSim. Optionally, you can download their desktop client; otherwise, search their site for instructions to configure your local repository for access to push your local changes to the remote. First look at the repository in the next step, anyway.
  5. SorpSim source code
    • Finally! Go here and click the Clone button to get instructions.

Now, open QtCreator. Select to open an existing project, and navigate to find SorpSim/src/SorpSim.pro, a Qt project file. You are then given options for which compilers and platforms to use; just pick a favorite and click to Configure (this create a new SorpSim.pro.user file for your local machine). The QtCreator then takes on the Editing mode appearance, and you can browse and open source files. First, you need to edit SorpSim.pro and make sure that all library paths are correct, specifically the Qwt library (include files, sources, and . (This initial setup could be done using CMake, but that requires some labor.) Save changes, and then use menus to Build > qmake, which generates a Makefile for your compiler. Now you are ready to build the project and run it.

Development branches

If you look at the GitHub page for SorpSim, you might see something like 2 authors. Clicking through shows that there are a number of parallel efforts. The developers may choose to synchronize changes into one main branch, but it is good to research which branch is most up-to-date and which developers are most active. Note: you can and likely should talk to them!

Building sources

Vcvars

In the past I had difficulty compiling code (namely the CoolProp wrapper for Python) using my VS compiler from command line. This may have something to do with the Universal CRT as claimed by MS, or may just be a bug of VS. In fact you need to follow those directions in order to install a working version of VS. Furthermore, in Windows 10, I found that executing a couple lines was necessary to include the VS command line tools correctly. The script is here and requires you to set the arguments on the first Call statement based on your desired platform; see here. You could try that, or try launching QtCreator via the command line from within a "Native Tools Command Prompt" of your choosing. With the latter approach, you need to include manually into the Path: Qt bin and Jom. Ugh, this needs re-writing.

Qwt

As the file qwt/INSTALL indicates, you need to read the documentation. (Basic prequisites: open a command line, make sure that Qt and your compiler tools are included in Path environment variable, etc.) To help compile faster, try multithreaded compile. Per the Qwt documentation, for MinGW, make takes argument -j, as in -j4 for 4 cores. For VS, the make tool is Nmake, which has no such option; see Nmake options. On the other hand, the compiler does understand multithreading: see here and here. The conclusion is that you need a replacement for nmake called JOM, which is conveniently provided by the Qt folks, and automatically used by QtCreator for VS projects. How about that?

Note that the Qwt project contains two targets to build: the library, and also a plugin for QtCreator, in the qwt/src/designer directory. Project settings are in the file qwtconfig.pri including a switch to control whether and how the plugin is compiled.

I built Qwt by opening the project file in QtCreator. By default, QtCreator makes a separate build directory to avoid polluting your source folder; then you will have to locate the include files and libraries for use by SorpSim. Also note that in the IDE, you can pass arguments to your Make program by entering the Projects mode (Ctrl-5) and expanding Build Steps > Make.

Anyway, compiling took a long time.

Compiler Flags Elapsed time
MinGW 32-bit None 29:31
MSVC 2017 64-bit jom -j4 03:15

SorpSim

Please note above hints for multithreaded compile. Once again, I opened the project file in QtCreator and compiled that way. Oh, and it looks like jom is now using all my cores without my asking.

Here are the typical results.

Compiler Lib versions Computer Extra flags Compile time
MinGW 32-bit Qt 5.9.3, Qwt 6.1.3, SorpSim 4751bf9 8x 3.6 GHz, 8 GB None Pending...
MSVC 2017 64-bit Qt 5.9.3, Qwt 6.1.3, SorpSim 4751bf9 8x 3.6 GHz, 8 GB None 00:58

So, wow, that's even faster than compiling qwt.

Initial fixes

As often happens in life, the code fresh from the published repository will not compile. Here are a list of changes required from the commit 4751bf9.

  1. Linker was complaining about finding the qwt library, so I let QtCreator automatically generate the specification for the external library into my SorpSim.pro file (and I deleted the manually included lines). The difference is at the end of the line an extra argument with lower case l for link, as in LIBS += -L<qwt path>/lib/ -lqwt.

  2. C-tyle array declarations converted to C++ vectors. I was getting errors about initializing arrays with non-constant expression. There were many declarations of C++ style arrays (with brackets[]), some containing Qt objects and many containing double, using variables as the size specifier. C++ wants an actual constant at compile-time, not a const variable. So I converted these to declarations of std::vector<T>. I wonder if extern "C" could get around that, but it is easy enough to stick with C++.

  3. Clean environment PATH variable. I had a DLL in my path that may overlap with system files, from MiKTeX. I removed MiKTeX from the PATH and continued (no change to code).

  4. Adjust linker argument order. I received a new error message that some symbol was unresolved (in my case, theTabledialog from tabledialog.cpp). It was defined properly in code. So continuing to search, I read that this error message may be related to the order in which linked libraries are specified. The project file SorpSim.pro lists the files to include in the project. Presumably these are passed as-is to the linker. So I moved tabledialog.cpp to just after the two files that use it. Edit: nevermind, this was not the problem.

  5. Change type of extern variables at global scope to match declaration with definition. A global variable theTabledialog was defined as QTableDialog* in tabledialog.cpp but included as tabledialog* in a couple other files.

  6. Include missing files (or drop unused files). The compiler could not find the header file ui_breaklinkdialog.h. This type of file gets generated by moc in the Qt build process, and its specification is a file breaklinkdialog.ui. That file exists; however, the file SorpSim.pro lists individual files to include in the Makefile, rather than directories, and this one wasn't listed, althought it was included by breaklinkdialog.cpp. However, that code is never used by the project, so we might as well drop it from the list!

  7. Note: compiling with MSVC, I get a false warning: ..\src\tabledialog.cpp(1841): warning C4189: 'fDialog': local variable is initialized but not referenced. However, the local variable is indeed referenced two lines later! So ignore that one.

At last, the code compiles and runs. I was even able to open one of the template files (by browsing). However, it crashed on my first attempt to calculate. So there may still be some debugging required! One more note, I can see from the provided systemSetting.xml that the last developer was trying to compile with MinGW 32bit and Qt 5.0.2. So I should probably try compiling with that as well.

In [ ]: