FFTW Logo
Go back to the FFTW Windows notes.

Using FFTW3 Visual C++ Library from Borland C++

Thanks to Klaus Maisinger for sending us the following notes on 14 Nov. 2003.

In case you (or someone else) might find this useful, I have attached a def- and lib-file required to link Alessio Massaro's fftw-3.0.1-w32-pl1.zip binary (13 November 2003) from fftw.org in Borland C++ Builder (the def file is not really necessary for linking). Below I have also attached some notes on how I produced these files - since I am more familiar with Unix than with Windows, this may not be a very elegant solution and look silly to more experienced users... :-)

Using FFTW3 Visual C++ Library from Borland C++

On the FFTW website http://www.fftw.org there is a Windows binary archive of FFTW 3.0.1 available for download; this has been compiled with the Intel Compiler. The archive contains (among others) a fftw3.dll and fftw3.lib. The fftw3.lib fails to link in Borland C++ Builder ("fftw3.lib contains invalid OMF record [...]"). This is due to an incompatible binary format: C++ Builder uses OMF, Visual C++ uses COFF formats. See http://www.bcbdev.com/articles/vcdll.htm for details.

There are two different calling conventions for functions in Windows: __cdecl and __stdcall. The default is __cdecl; since FFTW does not define any calling conventions, it uses __cdecl. With this convention, Borland C++ expects functions names to start with a leading underscore "_", whereas Visual C++ (and Intel as it seems) do omit the leading "_".

The workaround is as follows: start a command prompt, change to the directory where FFTW is installed and type "impdef rawfftw3.def fftw3.dll". This creates a "def" file from the DLL containing all the exported function names using Borland's impdef-utility. Now one has to create aliasses from the Borland function names to the exported names and add them to the "EXPORTS" section of the def-file. An example for an alias:

    _fftw_version                  = fftw_version

The following Python script def_cdecl_borland.py automates this task:

#!/usr/bin/env python
# this program automates the introduction of aliases for function
# names starting with a leading underscore for FFTW3 in a Windows
# def-file

import sys

if (len(sys.argv) < 3):
    raise "Usage: %s  " % sys.argv[0]

lines = open(sys.argv[1], "r").readlines()

outfile=open(sys.argv[2], "w")
outfile.writelines(lines)
exports=0
for line in lines:
    if (exports != 0):
        fields = line.split()
        if (len(fields)> 0):
            outfile.write("    _%-30s = %s\r\n" % (fields[0], fields[0]))
    if (line.find("EXPORTS")!=-1):
        exports=1

The script is called with the filenames for the old and new def-files as arguments ("def_cdecl_borland.py rawfftw3.def fftw3.def"). The last step is to create a "lib" file from the "def"-file: "implib fftw3.lib fftw3.def". The resulting fftw3.lib can be added to the C++ Project in C++ Builder and compiles.


Go back to the FFTW Windows notes.