I want to use fftw in my c++ program.
For this, I have installed petsc alongside the --download-fftw
option, since I want to be using Petsc in the future as well. I simply downloaded the most recent stable version, ran ./configure
with the respective options and then make
-> sudo make install
The files are now located in /usr/local/petsc
, which contain the following fftw files:
$ ls /usr/local/petsc/include/
...
fftw3-mpi.f03
fftw3-mpi.h
fftw3.f
fftw3.f03
fftw3.h
fftw3l-mpi.f03
fftw3l.f03
fftw3q.f03
...
$ ls /usr/local/petsc/lib/
...
libfftw3.a
libfftw3.la
libfftw3.so
libfftw3.so.3
libfftw3.so.3.6.10
libfftw3_mpi.a
libfftw3_mpi.la
libfftw3_mpi.so
libfftw3_mpi.so.3
libfftw3_mpi.so.3.6.10
...
I then defined my CMakeLists.txt
file for my project as following:
cmake_minimum_required(VERSION 3.0)
find_package(MPI REQUIRED)
add_executable(my_program my_program.cpp)
set(PETSC_DIR "/usr/local/petsc")
target_include_directories(my_program PUBLIC
${MPI_INCLUDE_PATH}
${PETSC_DIR}/include)
target_link_libraries(my_program PUBLIC
${MPI_LIBRARIES}
${PETSC_DIR}/lib)
In my_program
, I simply call fftw_mpi_init()
:
#include <mpi.h>
#include <fftw3-mpi.h>
int main(){
MPI_Init(NULL, NULL);
fftw_mpi_init();
}
However, this setup returns the error message
undefined reference to `fftw_mpi_init'
I realized that fftw_mpi_init
was not defined anywhere in my /usr/local/petsc
directory:
Is this related to my c++ program not being able to find the fftw functions? What steps do I need to take if I want to use the fftw installation that I downloaded alongside petsc?
EDIT: I also tried adding the lines
find_package(PkgConfig REQUIRED)
pkg_search_module(FFTW REQUIRED fftw3 IMPORTED_TARGET)
include_directories(PkgConfig::FFTW)
link_libraries (PkgConfig::FFTW)
to my CMakeLists.txt
file as suggested here, but I am still getting the same error undefined reference to fftw_mpi_init'
.