P3DFFT 编译 - "Undefined reference" 但库已链接

P3DFFT compilation - "Undefined reference" but libraries are linked

我需要编译 P3DFFT 方面的帮助。我真的迷失在这个过程中,因为编译器抱怨 "undefined reference" 很多符号,但这些符号存在于库中。

我的命令:

mpicc -g -O2 -I../../include -L/home/martin/fftw3/libs -lfftw3 /home/martin/p3dfft/build/libp3dfft.a driver_rand.c -o driver_rand

编译器输出:

driver_rand.c: In function ‘main’:
driver_rand.c:114:10: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
          fscanf(fp,"%d %d %d %d %d\n",&nx,&ny,&nz,&ndim,&n);
          ^
driver_rand.c:137:8: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
        fscanf(fp,"%d %d\n",dims,dims+1);
        ^
/tmp/cc52N8Sc.o: In function `Cp3dfft_setup':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:90: undefined reference to `p3dfft_setup'
/tmp/cc52N8Sc.o: In function `Cp3dfft_get_dims':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:100: undefined reference to `p3dfft_get_dims'
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:100: undefined reference to `p3dfft_get_dims'
/tmp/cc52N8Sc.o: In function `Cp3dfft_clean':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:95: undefined reference to `p3dfft_clean'
/tmp/cc52N8Sc.o: In function `Cget_timers':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:105: undefined reference to `get_timers'
/tmp/cc52N8Sc.o: In function `Cset_timers':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:110: undefined reference to `set_timers'
/tmp/cc52N8Sc.o: In function `Cp3dfft_ftran_r2c':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:117: undefined reference to `p3dfft_ftran_r2c'
/tmp/cc52N8Sc.o: In function `Cp3dfft_btran_c2r':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:130: undefined reference to `p3dfft_btran_c2r'
/tmp/cc52N8Sc.o: In function `main':
/home/martin/p3dfft/sample/C/driver_rand.c:106: undefined reference to `set_timers'
/tmp/cc52N8Sc.o: In function `Cp3dfft_setup':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:90: undefined reference to `p3dfft_setup'
/tmp/cc52N8Sc.o: In function `Cp3dfft_get_dims':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:100: undefined reference to `p3dfft_get_dims'
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:100: undefined reference to `p3dfft_get_dims'
/tmp/cc52N8Sc.o: In function `Cp3dfft_ftran_r2c':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:117: undefined reference to `p3dfft_ftran_r2c'
/tmp/cc52N8Sc.o: In function `Cp3dfft_btran_c2r':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:130: undefined reference to `p3dfft_btran_c2r'
/tmp/cc52N8Sc.o: In function `Cp3dfft_clean':
/home/martin/p3dfft/sample/C/../../include/p3dfft.h:95: undefined reference to `p3dfft_clean'
/tmp/cc52N8Sc.o: In function `main':
/home/martin/p3dfft/sample/C/driver_rand.c:258: undefined reference to `get_timers'
collect2: error: ld returned 1 exit status

libp3dfft.a 中存在未定义的符号:

nm ../../build/libp3dfft.a --defined-only | grep 'p3dfft_setup'
000000000000d030 T __p3dfft_MOD_p3dfft_setup
0000000000010ed0 T p3dfft_setup

nm ../../build/libp3dfft.a --defined-only | grep 'get_timers'
00000000000052f0 T get_timers
0000000000005230 T __p3dfft_MOD_get_timers

你知道我做错了什么吗?

我不熟悉您的特定编译器,但我认为您可能需要更正命令行中源文件和库的顺序,即

mpicc -g -O2 -I../../include -L/home/martin/fftw3/libs -lfftw3 /home/martin/p3dfft/build/libp3dfft.a driver_rand.c -o driver_rand

大概应该是:

mpicc -g -O2 -I../../include driver_rand.c /home/martin/p3dfft/build/libp3dfft.a -L/home/martin/fftw3/libs -lfftw3 -o driver_rand