Trying to use FFTW with NG

BlitzMax Forums/BlitzMax NG/Trying to use FFTW with NG

FireballStarfish(Posted 2016) [#1]
I am using the FFTW library in a BlitzMax program.

It's a C library that comes with a header file fftw3.h, and (in my case, as I downloaded the precompiled windows release) a libfftw3-3.dll and a libfftw3-3.def among other things. After a bit of experimenting, I found that by using MinGW's "dlltool" like
dlltool -d libfftw3-3.def -l libfftw3-3.a
I can turn the .def into an .a file which i can import with Import "libfftw3-3.a" (Import "-lfftw3" and such do not seem to work), allowing me to use the library in BlitzMax.
However, trying to do the same thing in BlitzMax-NG poses a problem. Externing FFTW's functions and calling them directly from BlitzMax code still seems to work, but calling them from a .c file does not.

A simple example would consist of a file "test.bmx" like this
SuperStrict
Framework BRL.StandardIO
Import "libfftw3-3.a"
Import "test.c"

Local p:Double Ptr = Test()
p[3] = 3
For Local i:Int = 0 Until 6
	Print p[i]
Next
fftw_free p
Input ""

Extern "C"
	Function fftw_free(p:Byte Ptr)		' void fftw_free(void *p);
	
	Function Test:Double Ptr()
End Extern

and a "test.c" like this
#include "fftw3.h"

fftw_complex* Test() {
	return fftw_alloc_complex(3);	// allocates an array of 6 doubles, basically
}


This works just fine for me in vanilla BlitzMax, but trying to build it with NG fails at the linking stage with the message "undefined reference to `_imp__fftw_alloc_complex'".
What can I do to get this to run? Is this a bug in NG perhaps?


Brucey(Posted 2016) [#2]
Assuming files are in the same folder, this should work:
Import "-L."
Import "-lfftw3-3"



FireballStarfish(Posted 2016) [#3]
Ohh thanks. I believe I actually tried this before, but only in vanilla BlitzMax, where it does not work. I'll put ?-conditionals around the imports then.
I have one more question: while this works when the .a and .dll are in my project rool folder (as in, where the .bmx is), is it also possible to put the library in a subfolder? I tried changing the first import to Import "-L./fftw-3.3.4-dll32" and putting the files in said folder, but the resulting "ld.exe: cannot find [...]" error tells me it's still looking for the .a in the root folder. I find this strange, because it does this despite the fact there's no Import "-L." anymore. (And it doesn't seem like it ignores that line and searches in the project root by default, since without any -L import, the build will fail even with the .a in the root folder.)


Brucey(Posted 2016) [#4]
I've generally done these things with modules.
ModuleInfo supports LD_OPTS..
ModuleInfo "LD_OPTS: -L%PWD%/somepath"

where %PWD% would resolve to the module path.