Problem linking a library

Hi

I have an algorithm programmed in C. I am trying
to link the FFTW3.3 library on it, both the
compilation and build of the executable are successful.

However, when I am executing the program I get a segmentation
fault when I call any of the FFTW functions.

This is the seg. fault:

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()

The funny thing is that I cannot see any mistake when
calling any FFTW function that could cause a seg. fault.
Additionally, I made the following small program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <fftw3.h>
#include <math.h>
#include "allocfun.h"
      
 int main(void){

   long n;
        n = pow(2,12);

   // the VECTALLOC function is defined into the allocfun.h file
   double *in_aty  = VECTALLOC (double, n); 
   double *out_aty = VECTALLOC (double, n);
   double *in_ax   = VECTALLOC (double, n);
   double *out_ax  = VECTALLOC (double, n);

   fftw_plan pln_aty;
   fftw_plan pln_ax;

   pln_aty = fftw_plan_r2r_1d(n, in_aty, 
                     out_aty, FFTW_REDFT01, 0);
   pln_ax  = fftw_plan_r2r_1d(n, in_ax, 
                      out_ax, FFTW_REDFT10, 0);
   FREE(in_aty);
   FREE(in_ax);
   FREE(out_aty);
   FREE(out_ax);
  
   /*fftw_destroy_plan(plan);
   fftw_free(data);*/
   return 0;
 }

that runs successfully and only uses the part of my algorithm that causes the problem.
. However, when I put exactly the same lines of code at the
very beginning of the main function of my program I get a seg. fault
in fftw_plan_r2r_1d.

I compile my program using the following make file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
include settings

OBJECTS= example.o 
OUTPUT = hmfext 

MYLIBS = -L ../../interface -linterface -L ../../source -lsource

MATLABDIR=/usr/local/MATLAB
MATLABLIBS= -Wl,-rpath-link,$(MATLABDIR)/bin/glnx86 -L$(MATLABDIR)/bin/glnx86 -lmex -lmat -leng -lmx
MATLABLINKERSONE= -I$(MATLABDIR)/extern/include
MATLABLINKERSTWO= -I$(MATLABDIR)/extern/include -DMX_COMPAT_32
MATLABLINKERSTHREE= -I$(MATLABDIR)/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fexceptions -D_FILE_OFFSET_BITS=64

#FFTWLIBS= -L /usr/local/lib -lfftw3
#FFTWLINKERS= -I/usr/local/include

.c.o:
	$(CC) $(CFLAGS) $(DEFINE) -c  $< -o $@ $(MATLABLINKERSONE) $(MATLABLINKERSTWO) $(MATLABLINKERSTHREE)

$(OUTPUT): $(OBJECTS)
	$(CC) $(CFLAGS) $(OBJECTS) -o $(OUTPUT) $(MYLIBS) $(LIBS) $(MATLABLIBS) -lfftw3

clean:
        \rm $(OBJECTS) $(OUTPUT)


while I compiled the small program using:

 
gcc -g test.c -lfftw3 -lm -o test


In case that it is useful I am givving the stack from the gdb:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()
(gdb) up
#1  0x00211c14 in fftw_kernel_malloc (n=4) at ../../../../sources/fftw/kernel/kalloc.c:62
62	../../../../sources/fftw/kernel/kalloc.c: No such file or directory.
	in ../../../../sources/fftw/kernel/kalloc.c
(gdb) 
#2  0x0021105a in fftw_malloc_plain (n=4) at ../../../../sources/fftw/kernel/alloc.c:268
268	../../../../sources/fftw/kernel/alloc.c: No such file or directory.
	in ../../../../sources/fftw/kernel/alloc.c
(gdb) 
#3  0x002fa3f7 in fftw_map_r2r_kind (rank=1, kind=0xbffff0dc) at ../../../../sources/fftw/api/map-r2r-kind.c:30
30	../../../../sources/fftw/api/map-r2r-kind.c: No such file or directory.
	in ../../../../sources/fftw/api/map-r2r-kind.c
(gdb) 
#4  0x002fbc14 in fftw_plan_many_r2r (rank=1, n=0xbffff0d0, howmany=1, in=0x80d80b0, inembed=0x0, istride=1, idist=1, out=0x80e00b8, onembed=0x0, 
    ostride=1, odist=1, kind=0xbffff0dc, flags=0) at ../../../../sources/fftw/api/plan-many-r2r.c:41
41	../../../../sources/fftw/api/plan-many-r2r.c: No such file or directory.
	in ../../../../sources/fftw/api/plan-many-r2r.c
(gdb) 
#5  0x002fbe7c in fftw_plan_r2r (rank=1, n=0xbffff0d0, in=0x80d80b0, out=0x80e00b8, kind=0xbffff0dc, flags=0) at ../../../../sources/fftw/api/plan-r2r.c:26
26	../../../../sources/fftw/api/plan-r2r.c: No such file or directory.
	in ../../../../sources/fftw/api/plan-r2r.c
(gdb) 
#6  0x002fbd31 in fftw_plan_r2r_1d (n=4096, in=0x80d80b0, out=0x80e00b8, kind=FFTW_REDFT01, flags=0) at ../../../../sources/fftw/api/plan-r2r-1d.c:25
25	../../../../sources/fftw/api/plan-r2r-1d.c: No such file or directory.
	in ../../../../sources/fftw/api/plan-r2r-1d.c
(gdb) 
#7  0x08049388 in main () at exampleMtxFree.c:141
141	  pln_aty = fftw_plan_r2r_1d(n, in_aty, out_aty, FFTW_REDFT01, 0);


To sum up, I have exactly the same piece of code in different programs,
compiled in a different way. One of them runs successfully while the other
fails!
Last edited on
1
2
Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()


That suggests a null pointer. Using gbd, print each parameter you're passing to fftw_plan_r2r_1d and see if any of them look suspicious.
That was the first think that I tried. As I said I put exactly the same piece of code into
both programs at the very beginning of the main function.

However, I just tried it again with gdb and I have the following output for the parameters of
fftw_plan_r2r_1d in the program that gives the seg. fault

1
2
3
4
5
6
7
8
(gdb) print n 
$1 = 4096
(gdb) print in_aty 
$2 = (double *) 0x807d0b0
(gdb) print out_aty 
$3 = (double *) 0x80850b8 
(gdb) print FFTW_REDFT01 
$4 = FFTW_REDFT01


All the parameters seem to be correctly initialized.
Last edited on
The fftw library was conflicting with the -lmx, -leng, -lmat, -lmex libraries of MATLAB.

I transferred the library libfftw3.a in my folder and linked it from there.
Last edited on
Topic archived. No new replies allowed.