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?

  • 9
    Sorry, this is obviously a major noob issue I'm having. How? There's no executable file. – Josh Friedlander Apr 20 '17 at 12:36
  • 6
    You probably need Windows SDK and the associated C headers to compile the program. Normally, the dependencies are mentioned and compile instructions are included in the Readme. In this case, neither is included, so you have to ask the repo owner/project author to get the relevant information. – Larssend Apr 20 '17 at 12:40
  • 7
    You do need a compiler. I would reach out to the dev and ask how to build it. Typically Linux software, for example, provided as source includes build instructions but I don't see any on his Github. – LawrenceC Apr 20 '17 at 12:40
  • 12
    You haven't downloaded an actual program, you have downloaded the source for the program and, yes, you do need to compile it first. Judging by the makefile in there you will need to build whatever it is in MINGW. – Mokubai Apr 20 '17 at 12:42
  • 21
    here is the executable github.com/renatosilva/winutils/releases – barlop Apr 20 '17 at 12:50
up vote 28 down vote accepted
+250

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:

  1. 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 Windows or <application name> exe.

  2. 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 Windows or MinGW 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 cmd or powershell:

      • 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: here helloworld.cpp is the name of the main source file, and helloworld.exe is the name of the compiled executable.
      • In case you have to compile multiple files list them before the -o switch: 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 .c instead of .cpp, and you should use the gcc command instead of g++. 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 probably definitely 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

  • Thanks, this is a great answer, and I've changed it to be marked as the definitive one. (I'd earlier edited my question to make it clearer that this was what I was looking for, but for some reason BoundaryImposition edited it out.) – Josh Friedlander Apr 23 '17 at 14:10
  • I don't think it satisfies Aibobot's bounty request, however, but that's between you and her/him. – Josh Friedlander Apr 23 '17 at 14:11
  • 2
    @JoshFriedlander Glad to be of any help! I'll add more to the answer later... Yep, I was chatting with JourneymanGeek (Aibobot), he's going to wait for a few days for new answers to surface. – rahuldottech Apr 23 '17 at 14:11
  • 1
    This project might not have any, but note that most projects will probably have dependencies, which means that if you're going the compilation route, you may need to track down the libraries that the software depends on, download them, and install them (or compile them as well). It's usually not as simple as just running the makefile; some of them may even have other build scripts such as cmake, configure script, etc. – jrh Apr 23 '17 at 18:58
  • 2
    Is the process really that simple in most cases? Which fraction of github utilities requires substantially greater knowledge to compile them than this what You’ve described here? – gaazkam Apr 23 '17 at 21:33

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.

  • 48
    Agreed. If you have to ask, you don't want to be compiling from source. – thunderblaster Apr 20 '17 at 16:59
  • 10
    If you have to ask, you probably shouldn't be installing software that's only available in source form... – jpaugh Apr 20 '17 at 19:15
  • 11
    I'm inclined to agree with @jpaugh. While it's very possible and sometimes necessary to build from source, it's not something that you can just go and ask "how do I build a C program" in a generic way. There's just too much variance. Some lucky programs are as simple as "compile these files". Others need makefiles. Some need dependencies to be downloaded first. The process of setting up for build can be complicated and isn't necessarily non-programmer friendly. Above all, though, you want to find a file in the project that explains how to build, because specifics are project dependent. – Kat Apr 20 '17 at 19:36
  • 35
    @jpaugh - I'd say you have a much better chance of installing malware by downloading an executable - malware is rarely open-source. – namey Apr 21 '17 at 0:22
  • 3
    Assuming you can actually read the language. I semi routinely compile stuff on linux and I can't/don't read any of the source. Even if i could, I'm not going to review every.single.line. – Journeyman Geek Apr 22 '17 at 0:36

.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.

  • 14
    If he had to compile it then it'd usually be explained in a readme, which you don't even mention he should look for. He is meant to go to the release page, it's not just "failing that(installing a compiler), that he should go to the release page" – barlop Apr 21 '17 at 12:53
  • 3
    mingw is also popular. – Zan Lynx Apr 22 '17 at 1:29
  • 1
    A specific project is usually tailored for use with a specific set of compilation tools (called a "toolchain") - which one it is is normally mentioned in a readme file (in UNIX and cross-platform projects, it's conventionally named BUILD or INSTALL). In less than stellarly maintained projects, or projects for environments with only a few well-known toolchains, a user is supposed to guess from the format and/or content of project files. – ivan_pozdeev Apr 22 '17 at 5:14
  • TCC? Really? You weren't serious, were you? – Yashas Apr 23 '17 at 6:56

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:

  1. If you're lucky, the project will provide build instructions, usually within the README file. Occasionally, there might also be an INSTALL file, 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.

  2. Lacking instructions, the next port of call is to check which build tool is required.

    1. If you find a file with a .sln or .vcxproj extension, 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).

    2. If you find a Makefile, this is probably going to require make. But this is where things get even more difficult, since there's so many independent and incompatible systems that use make.

      1. 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 run make.

      2. 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.

    3. The "build tool" could be a custom script by the name of build.bat or 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 of GCC, go back up to the 2.2.1. MinGW step but run the custom script instead of make.

  3. It's possible that there's no build tool at all. If all you encounter is a single .c or .cpp file, 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 either gcc or g++ as necessary -- e.g. gcc -o program.exe program.c

  4. It'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 make can usually be identified by the presence of a Makefile.

  • MSBuild is Windows-specific and is typically seen in conjunction with Visual Studio. These will usually be accompanied by a *.sln or *.vcxproj file.

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 Makefile too.

  • GCC (MinGW) is a port of GCC for Windows. Usually used with make. If the project is targeted towards Windows natively and has a Makefile, 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.

  • 1
    In this particular case the makefile gives you a good clue that it is for mingw as the first line is MINGW_PREFIX = $(shell which gcc | awk -F/bin/ '{ printf $$1 }') :) – DavidPostill Apr 23 '17 at 14:48
  • 1
    this one deserves the bounty imo – tbodt Apr 23 '17 at 17:32

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.