[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2 Compiling a Program with the WFDB Library

The WFDB library is developed and tested using gcc, the GNU C/C++ compiler, but careful attention has been given to making it usable with any ANSI/ISO C compiler. Since gcc is free, high quality, and supported, it is highly recommended that you use it for compiling your WFDB applications.

To compile the example program using gcc on a Unix shell, we can say:

 
gcc -o psamples psamples.c `wfdb-config --cflags --libs`

to produce an executable program called psamples. (Your C compiler may be named ‘cc’, ‘acc’, ‘CC’, or something else, rather than ‘gcc’.)

Note that this command contains backticks (‘), not apostrophes (’). The program wfdb-config is part of the WFDB Software Package, and tells the compiler where to find the header files (such as ‘wfdb/wfdb.h’) and the library itself (such as ‘libwfdb.so’). Writing the wfdb-config command in backticks means that the output of the command is inserted into the gcc command line. So if the WFDB library is installed in ‘/usr/local/lib’, then the command above is equivalent to:

 
gcc -o psamples psamples.c -I/usr/local/include -L/usr/local/lib -lwfdb

In addition to being shorter to type, it’s a good idea to use wfdb-config so that your program can be compiled on other systems, regardless of where the WFDB library has been installed.

You may use any other compiler options you choose, but ‘`wfdb-config --cflags --libs`’ must appear in the cc command line following any and all source (‘*.c’) and object (‘*.o’) file names, in order to instruct the loader to search the WFDB library for any functions that the program needs (in this case, isigopen and getvec). Some programs will need additional libraries, and the corresponding ‘-l’ options can usually be given before or after the wfdb-config command.

Under MS-Windows, ‘gcc’ is included in the freely available Cygwin software development system (http://www.cygwin.com/), and also in the freely available MinGW package (http://www.mingw.org/). An MS-DOS version of ‘gcc’ is available in the free djgpp package (http://www.delorie.com/djgpp/). These are used within a Cygwin terminal emulator window or an MS-DOS box in exactly the same way as described above for C compilers on all other platforms. For most purposes, Cygwin is recommended, since it provides a Unix-compatible standard C library (cygwin1.dll), so that applications behave exactly as they do on all other platforms. WAVE can only be built under Windows in this way. When building WFDB-based plugins for use with .NET applications or others such as Matlab that rely on the native Windows C library, however, the WFDB library must be recompiled to use the native library. This can be done using either MinGW gcc, or Cygwin gcc with its -mno-cygwin option.

If you choose to use an incompatible proprietary compiler, you are on your own! You may be able to create a linkable version of the WFDB library from the sources in the ‘lib’ directory of the WFDB source tree using a proprietary compiler, but doing so is unsupported (see your compiler’s documentation). If you are not able to build the WFDB library using your compiler, you can compile the library sources together with the source file(s) for your application. It may be easiest to copy the library sources (both the ‘*.c’ and the ‘*.h’ files) into the same directory as the application sources. If you follow this approach, find the directory that contains ‘stdio.h’ on your system and make a ‘wfdb’ subdirectory within that directory, then copy the WFDB library’s ‘*.h’ files into the ‘wfdb’ subdirectory (this is necessary so that statements of the form ‘#include <wfdb/wfdb.h>’ will be handled properly by your compiler). For example, to compile ‘psamples.c’ with Microsoft C/C++, set up the WFDB library source files as just described, then use this command:

 
cl psamples.c wfdbio.c signal.c annot.c calib.c wfdbinit.c

With Borland C/C++ or Turbo C or C++, substitute ‘bcc’ or ‘tcc’, respectively, for ‘cl’ in the command above. You will find that some WFDB applications do not need to be compiled with all of the WFDB library sources (for example, ‘psamples’ needs only ‘wfdbio.c’ and ‘signal.c’); in such cases, you may omit the unneeded sources for faster compilation and smaller executable binaries.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

PhysioNet (wfdb@physionet.org)