Home Research &
Strategy Consulting
Interop
Technology Center
Learning
Center
SUA Articles SUA Community
Forums
Tool
Warehouse
About
Interop Systems

Compiling Unix/Linux Programs with Interix/SUA on Windows

by Rodney Ruddock

Overview

Compiling programs, or building applications, on Interix and the Subsystem for Unix-based Applications that are Unix or Linux based can be done once the SDK's (Software Development Kits) are installed. This allows you to use, port or migrate Unix/Linux programs onto Windows while preserving the behavior and fidelity of those programs. This can be done for command line programs and GUI (X11) programs.

Starting by Installing the SDK's

For the fullest set of software development options you will want to have the tools installed that allow for compiling/building with both Microsoft Visual C (aka MSVC) and gcc.

Installing the Microsoft SDK's

If you have already installed both of the SDK's during the installation of the Microsoft Utilities then congratulations you have saved a step. If you have not yet installed anything then note that as you perform the installation you should select both the Interix/SUA SDK and the GNU SDK. It's easiest to do this during the initial installation for obvious reasons.

If you installed just the default selection with the Microsoft Utilities installation don't panic. Adding both SDK's later is not too difficult. You will restart the installation and select that you want to add the SDK's. When the installation re-starts you will be given three choices. Choose to add/remove components. You will then be presented with a tree-like set of options. The already installed components will already be selected. Select both the Interix/SUA SDK and the GNU SDK. This will get you the most installed (which is good). Then select "OK" to proceed.

If you have not previously selected to have the "SetUid" capability and to have "Case Sensitive" filesystems then you should select now to have them. This will improve what you can do on the system. It can also help smooth out any difficulties that you may not be aware of that can arise later. For example, if you have two files, "makefile" and "Makefile", on a Solaris system you expect them to be treated as separate files and used in a particular order. With case sensitive ON behavior with Interix/SUA will be as expected on Unix-like systems. Otherwise confusion can happen as one of the files clobbers the other or become inaccessible because the lack of case sensitivity makes these two files indistinguishable.

One of the special options that you can install with SUA is the ability to debug Interix/SUA programs that have been built with 'cc' or 'c89'. This article does not delve into debugging. So more details will saved for another article (or you can search the Forums now).

Updating the SDK's

Now that you have the SDK's installed you want to update the Microsoft versions and add a few more SDK tools. For example, the 'cc' compiler script that allows MSVC to be used has been updated at the SUA Community site at the request of Microsoft. You may also be interested in 'gmake' and several additional pre-built libraries. Having this all done for you can save you a lot of time and really get you bootstrapped on your project.

There are two ways you can update the SDK's. One way is to use the Developer Bundle here at SUA Community. The second way is to bootstrap the Interix/SUA installer onto your system and then pick and choose what you want from the Tools Warehouse after that.

Adding the Developer Bundle

Adding the developer bundle is quite easy. There are instructions on the same webpage that you can download the Developer Bundle from. You may want to install the Complete Bundle instead if you want all of the available software packages. The Complete Bundle includes everything in the Developer Bundle. You need to have Interix/SFU/SUA already installed plus the Microsoft Utilities and SDK. The Bundles are shown on the main page, but you can also get them from our ftp site.

Individual Selection of Software Packages

To individually select the software bundles you must have the Interix/SUA installer installed. From the Package Install Instructions web page you can choose the right bootstrap installation of the installer. Lot of additional information is there to about using the installer.

Once you have the installer you can pick and choose the individual packages you want to add. When you do install a package all of the other packages that are depended upon are installed too. This way you have everything functional.

You may install packages using the command line with the pkg_update command (as described on the Package Install Instructions web page), or you can make the selection from the Tools Warehouse directly. When you run the link (download/run) a small program is transported that will activate pkg_update for you.

Using the SDK Tools

You now have all of the manual pages, libraries and utilities that you want to build what you want. If not you may have some other packages to install.

You can compile programs directly using 'cc' or 'c89' if you want to use MSVC. Or you can use 'gcc' instead. Try out a "hello world" program or something like that in /tmp to see that everything is fine.

You may also want to use a build system such as 'make', 'gmake' or 'jam'. The 'make' utility is based on the Unix standard and works correctly with portable makefiles and also handles BSD specific extensions. If you have used non-portable 'gmake' extensions then you should use 'gmake' of course.

Several projects are using the GNU based "configure" scripts (there are other brands of configure scripts). This is worthy of a whole article on it's own. But I will mention that you should read the SUA Community FAQ Developer Section for hints on helping the configure work smoothly. This includes setting certain environment variables.

You should understand that using 'cc'/'c89' which invokes MSVC will result in binaries that are static only. MSVC cannot be used to create binaries that use shared libraries or to create shared libraries. A caveate to this is that 'cc' can create object files that will be used in shared libraries. The 'cc' compiler can be used to make 32-bit and 64-bit binaries (provided you have the 64-bit generating MSVC).

The 'gcc' compiler and friends can be used to create static binaries and binaries that use shared libraries and/or DSO's. This also provides a large degree of portability with compiler options because so many projects use 'gcc' as the default compiler.

If you have some code in your programs that needs changes for Interix/SUA you can guard them using the "__INTERIX" macro.

	#ifdef __INTERIX
	#endif /* __INTERIX */
	#if defined(__INTERIX) && defined(SOMETHINGELSE)
	#endif

Conclusion

A lot of Unix and Linux programs can be re-built on Interix and Subsystem for Unix-based Applications (SUA) with few to no changes. Having the additional packages from the SUA COmmunity Tool Warehouse can help make this process more rewarding (successful). Changes that are needed can often be restricted within makefiles (i.e. options to the compiler). Specific changes can be conditionalized so the same source code can continue to be updated uniformly with all of your systems.

© 2008. 2009 Interop Systems Inc.