SAS, GNU & Open Source: Mingw Development Tools and Sample

SAS, GNU & Open Source: Mingw Development Tools and Sample

Paper AD10 SAS, GNU & Open Source: MinGW Development Tools and Sample Applications Brian Fairfield-Carter, PRA International, Victoria, BC (Canada) Stephen Hunt, PRA International, Victoria, BC (Canada) Tracy Sherman, PRA International, Victoria, BC (Canada) ABSTRACT Although many products of the Open Source initiative have been successfully adopted in the SAS world (notably Linux, and the CVS/TortoiseCVS version control system), open source applications written by and for SAS users are somewhat under-represented. Of the 100,000+ applications currently registered on SourceForge (the world’s largest open source clearing house), a search for SAS-related applications currently yields fewer than a dozen projects. The willingness of SAS users to freely exchange ideas and source code is evidenced by the popularity of SAS conferences and by the wealth of information distributed on mail lists such as SAS-L, and tends to suggest motivations similar to those driving the development and distribution of open source software (namely the desire to increase the quality of software by allowing fellow programmers to freely read, modify and re-distribute source code). Cooperative development of SAS-specific open source applications would seem a natural extension of these same motivations. To set the stage for open source development targeted at SAS users, and under the assumption that the majority of readers are running Windows, this paper introduces the very basics of MinGW (Minimalist GNU for Windows), a pared-down collection of Windows-specific header files and libraries combined with various other GNU tools (most importantly GCC (the GNU Compiler Collection)). It provides basic information on distribution, set-up and configuration, and illustrates practical usage via two SAS-centric Win32 applications: the first is a simple log-checker, and the second, available on SourceForge under the name “ShellOut”, is a grid control and SAS code-builder for creating table shells. INTRODUCTION The world of open source/free software has evolved over the last twenty years or so under the central premise that better software and a stronger programming community result when source code can be freely read, modified and re- distributed. The basic idea is that bug fixes can be implemented by a potentially much larger pool of developers than under the traditional closed/proprietary model, and that because the same people often fill the role of developer and end user, features can be tailored precisely to match user requirements. Central to the Open Source initiative are the GNU operating system and the GNU toolset, cornerstones of the latter being the freely available and freely distributable header files and function libraries combined with the GNU Compiler Collection (GCC). These are what allow developers to build and distribute applications, and allow users to run these applications. GNU, MINGW, AND GCC GNU The term “GNU” is a recursive acronym standing for “GNU’s Not Unix”, and refers to a free, open source operating system created to mirror the functionality of Unix in a non-proprietary distribution. Rather than simply being free in a monetary sense, GNU is free in the sense of allowing open access to the source code, which can be modified, studied, borrowed from, and re-distributed. What we know of today as the Linux operating system is more appropriately referred to as GNU/Linux, reflecting its composition as a combination of the GNU system and the Unix- compatible kernel Linux. GNU/Linux and complete GNU documentation are distributed via http://www.gnu.org/. Large numbers of applications built using GNU tools are also available from http://sourceforge.net/, which is currently the world’s largest development and download repository of open source code and applications. Of particular note are TortoiseCVS, a graphical front-end to CVS (the Concurrent Versions System for version control of source code) (http://www.tortoisecvs.org/ ) (Williams, 2004) and wxWindows/wxWidgets, the class library on which TortoiseCVS is built (http://wxwindows.org/ ). MINGW AND MSYS Minimalist GNU for Windows (MinGW) is, as the name suggests, a minimal subset and Windows-specific ‘version’ of GNU, consisting of Windows-specific header files, binary utilities, and a Win32 version of GCC (the GNU Compiler 1 Collection), and which collectively provides all the functionality necessary to build Windows desktop applications. MSYS (‘Minimal SYStem’) is essentially a command-line interface, providing a convenient portable-operating-system- styled (POSIX) environment in which to run GCC and other MinGW utilities. MinGW and MSYS can be acquired from the download page at www.mingw.org as single-archive distribution packages, in the familiar form of Win32 installation binaries. This not only streamlines installation, but also ensures compatibility between different components of the distribution. Components can also be downloaded and updated individually. GCC Apart from the kernel, which actually runs applications, probably the most important part of any development environment is the compiler – the application that translates higher-level ‘human-readable’ code into low-level executable code. In MinGW, this functionality is provided by GCC. GCC is very versatile in that it includes front ends for C, C++, Objective-C, Fortran, Java and Ada, as well as standard libraries for these languages. Complete documentation to GCC is available at http://gcc.gnu.org/. PROGRAMMING LANGUAGE AND APPLICATION INTERFACE: C++/WIN32 API The two applications presented in this paper are both written in C++, and use the Windows 32-bit Application Interface (Win32 API). The Win32 API is the facility in Windows which controls user interaction with the operating system. It is what you see when you launch a desk-top application, and is responsible for drawing windows and other graphical elements on the screen, and for handling events that arise from actions in the user interface. MinGW provides access to the Win32 API by means of the ‘windows.h’ header file and associated library. These components supply a large number of functions for creating and controlling windows and the Windows Graphics Device Interface (GDI). While C++ (essentially an object-oriented ‘extension’ of C) might seem an archaic choice, there are things to be said for it. For a start, huge numbers of applications are and continue to be written in C++; documentation and sample code are extensive. Learning C++ is a worthwhile exercise if for no other reason than that it will make learning things like Perl, Java and Python much easier. If you’ve never worked with C++ and find the prospect intimidating, don’t worry – the authors were in exactly the same position a year ago! MINGW/MSYS USAGE ILLUSTRATED To illustrate the very basics of compiling and running an application built on MinGW, we’ll start with the inevitable ‘hello world’ program in c (source code assumed to have been saved as the file ‘hello.c’): #include <stdio.h> main (){ printf("Hello\n");} The first line of the program ‘#include’s a header file (stdio.h) (much like the “%include” directive in SAS), which contains function ‘prototypes’ for processing standard input and output. This header file resides in the “include” subdirectory under the MinGW parent directory; the function definitions themselves exist in compiled object files (libraries) under the “lib” subdirectory. While the source code behind this function implementation is available, it is not included in the MinGW distribution since it would very rarely be necessary to re-compile these libraries from source. The only part of the ‘hello’ program that actually does anything is the call to the ‘printf’ function, which writes “Hello” (followed by a newline character) to standard output (the command interface, in this case). To compile and run this program, we’d (1) launch MSYS and navigate to the directory containing the source file, (2) invoke GCC, passing it the name of the source file (hello.c) and specifying the name of the compiled output file (hello.exe), and (3) type the name of the compiled executable: Figure 1: Compiling and running a simple program using MSYS/MinGW 2 In reality, an entire application is seldom compiled from a single source file. A typical Windows application will consist of at least a header file (containing function prototypes and global declarations, and which is #included by a source file) and a resource script containing menu and dialog definitions. To build such an application, the source file and resource script are compiled into object files, and linked into the executable file. This would be carried out by something like the following: g++ -c myapp.cpp windres -o resource.o resource.rc g++ -o myapp myapp.o resource.o -mwindows Note that the C++ compiler is invoked via ‘g++’, and that the resource script is compiled by a resource compiler (‘windres’). The third line takes the compiled object files from the previous two commands and ‘links’ them into the ‘myapp’ application. THE GNU ‘MAKE’ FACILITY The preceding example shows that with even a small number of source files, compiling each file separately and linking into an executable would serve as a serious impediment to the development process. Consider what would happen as an application grew to 50 or more source files. Fortunately the MinGW distribution includes the GNU Make facility, an application that takes as input a user-defined ‘makefile’ (essentially a script describing how to build the application), and passes all the instructions required to build the application to the command interface. The Make facility allows the user to specify dependencies between source files, so that components are compiled and linked in the appropriate order, and can also recurs through directory trees so that neither source files nor sub-directories need to be explicitly referenced. One of the central features of Make is that it compares the timestamp on source files against that of compiled object files, and only re-compiles where the source files have changed since the last build before re-building the application.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    12 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us