Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7110 Discussions

Linking fftw interfaces using CMake in Visual Studio Code

phoenixSeven
Beginner
502 Views

Hello everyone. I want to use the FFTW interface provided by Intel oneAPI (MKL). I have pre-created the library fftw3xc_intel.lib using the command "nmake libintel64" in the command line with initialized oneAPI environment (using setvars.bat). Now I want to use the generated library in my project. However, it seems that generated *.lib file is not recognized by the project, and I get following errors during the linking stage:

main.cpp.obj : error LNK2019: unresolved external symbol fftw_create_plan in function main.
main.cpp.obj : error LNK2019: unresolved external symbol fftw_one in function main.

The build commands I am using in the VS Code Terminal:

/build> cmake .. -G "Ninja"
/build> ninja

 
Here is my main.cpp

 

#include <fftw/fftw.h>

#define N 100

int main(){

    fftw_complex *in  = (fftw_complex *)fftw_malloc(N);
    fftw_complex *out = (fftw_complex *)fftw_malloc(N);
    fftw_plan a = fftw_create_plan(N, FFTW_FORWARD, FFTW_ESTIMATE);
    fftw_one(a, in, out);


    fftw_destroy_plan(a);
    fftw_free(in); fftw_free(out);
    return 0;
}

 

 
Here is my CMakeLists.txt

 

cmake_minimum_required( VERSION 3.18 )


project(FFTW_TEST LANGUAGES CXX)

find_package( MKL REQUIRED )

add_executable( test main.cpp )

target_link_libraries( test MKL::MKL )
target_link_libraries( test "C:/Program Files (x86)/Intel/oneAPI/mkl/2025.0/share/mkl/interfaces/fftw3xc/fftw3xc_intel.lib" )

# target_link_directories( test PRIVATE "C:/Program Files (x86)/Intel/oneAPI/mkl/2025.0/share/mkl/interfaces/fftw3xc")
# target_link_libraries( test fftw3xc_intel )

 

 

What am I doing wrong or missing?

Labels (3)
0 Kudos
1 Solution
Aleksandra_K
Employee
361 Views

The problem you're facing may be caused by the fact that the functions fftw_create_plan_plan and fftw_one are not in the fftw3xc_intel.lib library, but they are in the older version of the library - fftw2xc_intel.lib. (For more information about the difference between fftw2 and fftw3 please refer to https://www.fftw.org/doc/Upgrading-from-FFTW-version-2.html )

 

You can try to use fftx2xc instead, but note that the fftw2xc library builds in a different directory, that is in CMakeLists.txt you should also change from

target_link_libraries( test "C:/Program Files (x86)/Intel/oneAPI/mkl/2025.0/share/mkl/interfaces/fftw3xc/fftw3xc_intel.lib" )

to

target_link_libraries( test "C:/Program Files (x86)/Intel/oneAPI/mkl/2025.0/lib/fftw2xc_double_intel.lib")


View solution in original post

0 Kudos
2 Replies
Aleksandra_K
Employee
362 Views

The problem you're facing may be caused by the fact that the functions fftw_create_plan_plan and fftw_one are not in the fftw3xc_intel.lib library, but they are in the older version of the library - fftw2xc_intel.lib. (For more information about the difference between fftw2 and fftw3 please refer to https://www.fftw.org/doc/Upgrading-from-FFTW-version-2.html )

 

You can try to use fftx2xc instead, but note that the fftw2xc library builds in a different directory, that is in CMakeLists.txt you should also change from

target_link_libraries( test "C:/Program Files (x86)/Intel/oneAPI/mkl/2025.0/share/mkl/interfaces/fftw3xc/fftw3xc_intel.lib" )

to

target_link_libraries( test "C:/Program Files (x86)/Intel/oneAPI/mkl/2025.0/lib/fftw2xc_double_intel.lib")


0 Kudos
phoenixSeven
Beginner
292 Views

Thanks for your reply! I really missed that this is fftw2.0 functions. I also changed my include to #include <fftw/fftw3.h> and now everything works fine. I also dont need to use target_link_libraries() in CMakeLists.txt

0 Kudos
Reply