I've downloaded a dead simple Windows program from GitHub (this if it's relevant). I downloaded it as a ZIP file, but I can't figure out how to install it. It's written in C, I think. Do I need a compiler? (Visual Studio?) Is there something simple that I'm missing?
4 Answers
You look around and find the installer on the release page. Sure you could compile the source, but I don't think that's what you want.
- 133,878
.c and .h files are C source code.
You will need to install a C compiler such as Visual Studio, tcc or something similar, load the project and then compile it to run it.
Failing that, the project has a release page (here) that will give you access to a pre-compiled version to save you time and effort.
- 12,326
- 12,965
Github is primarily used by programmers to collaborate on projects. The 'Download ZIP' option downloads a copy of the source code to your computer. This usually1 doesn't contain a copy of the compiled usable executables/binaries (ie; exe files)
Releases, is a Github feature for shipping software to end users (who usually aren't interested in the actual coding). Releases are accompanied by release notes and links to download the software or source code. This is the first place you should check for binaries.
In your case, the releases page offers downloads and setup files.
However, many projects won't have any releases (especially not for Windows), in which case you can do one of the following:
Search for binaries elsewhere on the internet. Usually search engines like DuckDuckGo (or Google, if you prefer) will find what you want easily. Try searching for
<application name> for Windowsor<application name> exe.Compile it yourself. You need to have at least some basic knowledge of the programming language to be able to do so. Here again, search engines can be massively helpful. Try searching for
compile <application name> on WindowsorMinGW compile <application name>.Here I'll run through the basics of compiling utilities for Widnows:
Download MinGW. I personally favor this package because it comes with boost (which several applications use) and a cool shell. It also comes with
git, which can be super useful if you want to compile files hosted on Github or other Git version control repositories without having to separately download the source.Run the following commands in
cmdorpowershell:cd c:\sources\hello: Change the directory to wherever it is that the source file(s) is/are located.g++ helloworld.cpp -o helloworld.exe: herehelloworld.cppis the name of the main source file, andhelloworld.exeis the name of the compiled executable.- In case you have to compile multiple files list them before the
-oswitch:g++ helloworld.cpp foo.cpp -o helloworld.exe - These are the instructions for C++. If you're dealing with applications programmed in C, the file extension will be
.cinstead of.cpp, and you should use thegcccommand instead ofg++. The rest is more or less identical - Note that you may need to specify more command line arguments in order to compile an executable which works properly. The project page will usually have these details.
- You also
probablydefinitely want to look into makefiles. This Stack Overflow post is about makefiles in general, and this one tells us how to use them with MinGW. If a project comes with a makefile, try it before manually compiling the source. - You should now be able to run
helloworld.exe.
- Note: Most projects come with a README file. Please do what the name implies, these files contain important information regarding compiling and running software and by reading it you can avoid a lot of unnecessary hassle.
1Note: Sometimes there may be a folder called bin among the downloaded files, which should contain usable executables/binaries
Also see Cygwin and GOW if you want GNU/Linux command line utilities on Windows. I make some the latest version of some useful executables available for download here.
Further reading:
http://www.mingw.org/wiki/MinGW_for_First_Time_Users_HOWTO
https://gcc.gnu.org/onlinedocs/index.html#dir
https://stackoverflow.com/questions/22873884/how-do-i-run-configure-with-mingw
- 6,129
This answer will be addressing the general question of building a source-only Windows application (in C). If you're lucky like the OP, you might be able to find precompiled binaries.
The first thing to be aware of here is that there's no single way to build an app from source. There are approximately as many variations as there are different projects. That said, here are some general steps:
If you're lucky, the project will provide build instructions, usually within the
READMEfile. Occasionally, there might also be anINSTALLfile, or other documentation available. If those are available, follow the instructions. They're your best bet.As others have said, unfortunately, it's very difficult to reconstruct the required build steps without instructions. However, we can at least make a best-effort attempt here, which will work for most simple projects.
Lacking instructions, the next port of call is to check which build tool is required.
If you find a file with a
.slnor.vcxprojextension, this is probably a MSBuild/Visual Studio project. Download a copy of Visual Studio Community or Express (for C++), open that project file in there, and click the play button in the toolbar (or use the build menu).If you find a
Makefile, this is probably going to requiremake. But this is where things get even more difficult, since there's so many independent and incompatible systems that usemake.Since it's targeted towards Windows, it's probably going to use MinGW. Download a copy of that, launch MSYS from your start menu, navigate (
cd) to the directory that contains your project, and runmake.On the rare occasion that it's Cygwin instead (there's no easy way to tell, unfortunately, but if the MinGW build errors out with a "posix"-related error, this is a decent bet), you'll have to install Cygwin instead. Unfortunately, this does not build native Windows binaries -- you'll have to launch the program through Cygwin every time.
The "build tool" could be a custom script by the name of
build.bator similar. In this case, you'll have to either open it up and see what's inside, or try running it and see what the errors are. If you open it and see mentions ofGCC, go back up to the 2.2.1. MinGW step but run the custom script instead ofmake.
It's possible that there's no build tool at all. If all you encounter is a single
.cor.cppfile, then it's probably simple enough that you can do a straight compile. These are, again, almost always MinGW, so download that, launch the MSYS shell, navigate to the directory, and invoke eithergccorg++as necessary -- e.g.gcc -o program.exe program.cIt's possible that none of these work. If you got error messages at any step, they might contain a clue of what's missing. One possibility is that you were lacking certain required frameworks or libraries -- if you feel up to it, you can try downloading those and adding them to your build environment, but this is typically not a trivial process and has so many variations there is no way to cover them in an answer.
Glossary
Build tools
A build tool allows you to build a project with very few commands. For most projects with more than a single source file, a build tool will be involved somewhere. There are several build tools, but the most common are:
make, used everywhere on Linux and increasingly common on Windows. Projects using
makecan usually be identified by the presence of aMakefile.MSBuild is Windows-specific and is typically seen in conjunction with Visual Studio. These will usually be accompanied by a
*.slnor*.vcxprojfile.
Toolchains
A toolchain is the compiler and supporting tools. Just like the build tools, there are several, and they're usually used with one of the build tools.
MSVC is Microsoft's toolchain. This is the most common toolchain for Windows native development. This is usually used with the MSBuild system, and builds are usually created through Visual Studio. However, modern MSVC projects can use
Makefiletoo.GCC (MinGW) is a port of GCC for Windows. Usually used with
make. If the project is targeted towards Windows natively and has aMakefile, it's probably for MinGW-GCC.GCC (Cygwin) creates a POSIX-compatible environment. This allows you to directly compile most programs written for Linux or Unix and have it work directly under Windows. More recently in Windows 10, Bash on Ubuntu on Windows is an alternative. GCC is usually used in conjunction with
make.
Frameworks and libraries
Libraries are reusable sets of code written by other people, that many programs depend on to avoid reinventing the wheel. You need to have these dependencies available in order to build the project. If you're lucky, they'll be included with your initial download, but this is not always the case.
Frameworks are effectively a collection of libraries. Many projects use one framework, which you'll also need. These often come with their own build system too, but listing them all would be impossible.
The hardest part is dealing with extra framework and library dependencies. If, say, the project uses Qt -- then you'll need that whole mess to build it properly. This is a huge undertaking, and unless you have prior experience it's probably better to just ask others for direct help here.
- 63,170