C++ – How to distribute the scientific software with as few dependencies as possible

cdependencieslibrariesportabilitysoftware

As part of my research, I write a lot of Python and MATLAB code that never needs to be distributed to anyone else. Even if I need to distribute my software, Python and MATLAB, both being interpreted, make sharing it relatively simple.

Now I am writing some software in C++ that I'd like to distribute. I have a handle on how to compile the software on my own machine, but what I don't have an understanding of is what needs to be done in order to give other people the software.

First, more about my project: I'm writing some code to compute and display visualizations. The project is graph-based, and so I am using the LEMON graph library. I'm exploring VTK and OpenGL implementations for the purpose of displaying the visualization. I'd like to write Python and MATLAB bindings for users of those environments to be able to use my software, and I'd like to produce Windows and Linux versions (I haven't thought about OS X yet…).

So, let's take the LEMON graph library as an example. It is a bunch of headers along with a small shared object. On my development system, I compile the library with CMake and link it with my project.

Now say I want to give my software to someone running on Windows. I want them to be able to download an installer, click a button or two, and have everything taken care of. I don't want them to worry about installing the LEMON library, or OpenGL. They shouldn't have to knowingly compile anything. Is this possible?

I have a feeling it is, but I come up short when searching for references. I have a vague idea that if I compile a binary on Windows I should be able to distribute that binary to anyone running a Windows OS. But what about the libraries I use? I'm guessing I need to statically link them on Windows, and that will take care of the dependency issue there. But in the back of my mind I have read that statically linking is not good practice (or is this just on Linux?)

As you can tell, I'm somewhat lost. I'd appreciate a nudge in the right direction, and some references to read if you happen to know of any!

Best Answer

So long as the licence of the VTK libraries permits it, you might be able to write an NSIS Installer script (which will create a redistributable installer) that will install the VTK libraries in quiet mode. Quiet mode (if the VTK installer has this) will install the libraries without prompting the user for any input - this is how most video game installers work (required software is installed without prompting you to agree to the terms of use, or where to install it).

However, just blindly installing extra software might leave you in a precarious legal position. I'm not entirely sure on the legality of it, but I'd guess that you have to inform the user of all of the extra software you are about to install on their machine.

As an example, one of the installers I've scripted (for a product I work on) requires SQL Server 2005 to be installed alongside the binary. In the install script, if the user's machine doesn't have the required version of SQL server (or later) installed, it calls the MSI file for SQL Server 2005 (packaged within the NSIS installer) with the /q switch. This installs the SQL server with default settings, and all the user sees is the "installing SQL server 2005" prompt that get's thrown up whilst the MSI does it's work. We make a point of informing the user about this, and giving them the choice to install our software without it.

You might be able to create a make that will build all of your libraries for you, then call the NSIS script builder, but I'm not sure. I've not looked that far down the rabbit hole for NSIS, as we're not automating out installer builds.

Of course, you can replace NSIS with any other installer scripting environment. I've only used it here as an example, because I have a little experience with it.

Related Topic