How can a program create another executable file? - c++

Basically I'm asking how do installers work. What is the code that creates a new executable file?
EDIT: It sounds like the answer I'm looking for is the files are stored in archives and the installer unpacks them.

An installer normally extracts an appended archive and puts it to the desired directory, registers some libs and so on.
Another Task of an installer is to detect if the needed dependencies are installed and install them if needed.

Related

Building a Qt executable in Visual Studio 2017

I made a Qt Application in Visual Studio and it works when I run it in the program. However then I build the solution and try to run the executable errors pop up that certain .dll files are not found(QtWidgets.dll, QtCore.dll,QtCored.dll etc.). How can I fix this?
To make your application ready for deployment, you can use windeployqt.
It is a commandline program that comes with Qt and collects all the required dependencies of your executable. Go to your QTDIR/bin/ folder and run this command
windeployqt <path-to-app-binary.exe>
It will scan your binary and copy everything that is needed next to it. For further details, have a look at the documentation.
Well, you have two options:
If you want to distribute your application, you have to copy the required DLLs to the folder where your executable is. You can do this either by copying them manually or you write a script for this. The DLLs are in the binary folder of your Qt installation, e.g.
Qt\5.12.2\mingw73_64\bin
Add the above mentioned folder to your system PATH variable, then the DLLs should be found by your application.

build c++ (qt) program as one portable file with built-in dependences

I have a Qt project. I can build it but I have to keep all external files near with the executable one if I want to use the exe-file as portable program. But a customer wants it to be an one executable without any other files. The size of result file does not matter.
So, if I would use Python, I could do it like this:
[localhost#localhost ~]$ pyinstaller --onefile myscript.py
Can I do the same using Qt (with MinGW)?
It depends on the files you are talking about. With static linking you can get rid of dll files and by using Qt resource collection files you can for example link pictures and html files into your executable.
You could package your bundle into a self-extracting ZIP that automatically runs and cleans up after itself. I found this answer that gets you close.
You can't unless you have a commercial Qt license or if you don't link to any of the Qt libraries (you could still use Qt creator and qmake).

Running my GIS application using dev-c++ gives "gdal201.dll is missing"

I'm working on a GIS application in C++ using Dev-C++, and to start for now I'm using the code given in the tutorial in Link
I got it to compile without errors or warnings, but when I try to run it I get the error "The program can't start because gdal201.dll is missing from your computer. Try reinstalling the program to fix this problem."
I was looking at another question with the similar problem and tried to search this dll on internet, but couldn't find it anywhere, and somebody mentioned to ignore the error, but I don't know how to do that.
Can anybody help me on what to do here?
Thanks in advance.
You need the DLL file(s) to be present either in the same directory as the executable, or in your Path variable for the system to be able to find them. I personally prefer setting Path. You might consider either adding GDAL_DIR\bin to your permanent Path by editing system or user environment variables, or else create a small batch file on the desktop which adds the directory to Path then starts devenv.exe if you need to manage several incompatible development environments for different projects.
(This has several advantages in my experience over copying the DLL files to the same directory as the executable: It's easier to manage dependencies by including all the necessary directories, as opposed to manually tracking down all the recursive dependencies. It's also easier to manage updates of the DLLs if you can just update the GDAL installation directory, or update Path or the batch file to a newer GDAL installation directory, rather than having to track down all the places you've copied the DLLs to or having to manage post-build scripts to copy the DLLs every time.)
(Of course, when it comes time to create a self-contained installer, it's going to be easiest to copy the dependent DLLs to the installer image directory before building the installer. Then something like CMake's BundleUtilities module can help in tracking down what DLLs need to be included.)
Usually I copy private DLLs to the output folder of the project, i.e. the same folder as the executable. For a commercial application, you may want to install the DLL, let the OS handle the management of it and use the Assemblies Manifest to help the loader find it.

How do I set a lua.dll so lua.exe won't ask for it in every directory?

Every time I enter lua my_script.lua in command line, it prompts me for lua53.dll on the same folder. How do I set a path so I won't need to have a copy of the lua library in every folder that I want to run a .lua file? I wonder if it is made via parameters or if I should build my own .exe from the .c files using environment variables, but I don't really know.
I've downloaded the binaries from http://luabinaries.sourceforge.net (v5.3.2 - may 19th) and have put lua.exe inside C:/Windows/System32.
According to this MSDN article, the directory from which the application is loaded is the first location being checked for the DLL file. If you put the DLL next to the location of lua.exe it came with, the DLL should be found and loaded by the system.
It may be better to not put application files into your system folders. Just create a separate folder and put your Lua files (.exe and .dll) there. You can then add that folder to PATH environment variable, so that it can be found when you run it as lua.

Build all dependencies to one file

I'm working on a small installer program (silent install of setup, unzipping, ...).
I wondered how to build everything into one .exe file.
I don't even know HOW to search for that correctly.
Could you tell me some keyword to search for?
E.g.:
I have Setup.exe and Configs.zip for my installer to use.
After compiling I just wanna have 1 file (Install.exe) which has Setup.exe and Configs.zip included and can use them.
You could use resources that is a normal way to store such files. You can extract that files and execute that than from the temp directory.