[ < ] [ > ]   [ << ] [ 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, we can say:

gcc -o psamples psamples.c -lwfdb

to produce an executable program called psamples. (Your C compiler may be named ‘cc’, ‘acc’, ‘CC’, or something else, rather than ‘gcc’.) You may use any other compiler options you choose, but the ‘-lwfdb’ option 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 ‘-lwfdb’ option.

If the WFDB library was installed with NETFILES support, it will make use of functions contained in the libcurl library. If you have a dynamically linkable version of the libcurl library, as under GNU/Linux, these will be loaded automatically when you run psamples. If you have only static versions of these libraries, however, it is necessary to provide additional arguments in the cc command line in order to compile successfully. One way to do this is to follow the model used to compile the standard WFDB applications supplied with the WFDB library; see ‘Makefile’ in the ‘app’ directory of the WFDB software package source tree.

If you are using WFDB version 10.2.6 or a later version and ‘gcc’ or a compatible compiler, the ‘wfdb-config’ utility is available to help construct commands for compiling programs that use the WFDB library (and the libcurl library, if available). Use it like this:

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

Note that this command contains backticks (‘), not apostrophes (’). ‘wfdb-config’ is particularly useful if the WFDB library or its ‘*.h’ files are installed in non-standard locations, or if you have only a static libcurl library.

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)