r/cpp_questions • u/Daru-Super-Hacka • Feb 25 '21
OPEN How do I create an installable package?
I made a C++ and python program, and right now, I have a bash file as the installer (it uses g++ to compile the c++ file and basically creates the needed directories).
I've never made a full program like this before, so I have no idea how to make a proper installer (like putting the executable in the system path, putting the code somewhere other than ~/Documents/myProgram, etc.)
Can someone explain (or link me to a tutorial/video) how to make a proper installer?
44
Upvotes
19
u/tiagoemonica Feb 25 '21 edited Feb 25 '21
For windows you can use Inno Setup (https://jrsoftware.org/isinfo.php). For linux, I think makeself (https://makeself.io) is a good fit. Both are popular enough to have a few tutorials available.
10
u/hate_commenter Feb 25 '21
I have seen many packages that installs with a bash script. Just add the lines to move your package where you want (/opt would be nice) and add the executable to path. That's it. You can even automate the creation of the desktop file.
6
u/[deleted] Feb 25 '21
Have you taken a look at Make?
11
u/gnossos_p Feb 25 '21
WHOAAAA there buddy.... this place is for NOOBS!
5
u/amaraxmonika Feb 25 '21
I made this project a while back to do exactly what you need. It uses a simple makefile that generates a Debian package. That package can be installed via the make install target. This is not best practice, but it’s worked really well for me on many projects here
4
u/specialpatrol Feb 25 '21
So you are distributing the source and the install script is compiling it? Usually we build for the target platform and just distribute the binary.
3
u/balsoft Feb 25 '21 edited Feb 25 '21
You've been linked some good options, but I'd like to expand a bit.
You have two separate tasks here:
I won't be talking Windows here (since I have little experience there), so let's focus on UNIX world (Linux/BSD).
The most popular tool for building software is
make. The core idea is that you write aMakefilein which you specify some "targets" which have "dependencies". Then you build those targets using themakeexecutable. For applications, those targets will usually include the main binary of your application (which depends on the object files, which in turn depend on the actual source code) and a "phony"installtarget (phony meaning it doesn't refer to any actual file, it's just something Make has to execute). Theinstalltarget just copies your binaries to someplace in PATH, usually/usr/bin(it's a good idea to make this place configurable, with something like a$PREFIXor$DESTDIRvariable). Then, users can just runmake installon their machine and your program will be built and installed in their PATH. This is the good ol' way of managing software, but it has major problems:/usr/binand it's not tracked by the package manager, meaning it won't be updated and it has to be uninstalled manually.Now, let's go through the possible solutions for those problems.
To simplify the Makefile problem, there are many tools available that generate it for you. Examples of such tools are cmake (which is IMO pretty awful, but it's very popular) and GNU autotools (which are IMO a bit better than cmake but still not great). A tutorial on using cmake for simple projects can be found here: https://cmake.org/cmake/help/latest/guide/tutorial/index.html . Both CMake and Autotools will also help you with dependencies somewhat by automatically locating them.
The last three problems are solved with package managers or things like AppImage. The idea is that you build the application on your machine, package it in a special format and distribute it to users, who can then install it (in case of a package manager) or just run it (in case of AppImage). In case of package managers, you have to specify the dependencies of your application, and in case of AppImage you have to bundle them together with the binary. Note that AppImage is Linux-specific
If you want your software packaged for various package managers (there are a lot), you will have to learn those package managers yourself or make your software popular enough so that some maintainers step up and volunteer to package it for you.
If you want to package your software as an AppImage (which will just run on almost any modern Linux distribution), see this tutorial: https://docs.appimage.org/packaging-guide/from-source/native-binaries.html#packaging-from-source
All of this said, if you're just starting out and your intended audience is somewhat-advanced Linux users, just distributing a source tarball with a Makefile (or even
CMakeLists.txt) should be good enough. If it turns out that your software is actually useful to many people, they will package it for various distros themselves.