2
votes

During the setup of my project - when I knew even less than I do now about cmake - I was trying my hardest to link the FFTW library.

C:\\path\\to\\fftw-3.3.5-dll64 contains the .h files, .lib files (generated from .def files) and .dll files.

What I ended up doing was adding these links to my CMakeLists.txt:

add_executable(${TargetName} PRIVATE main.cpp)
target_include_directories(${TargetName} PRIVATE "C:\\path\\to\\fftw-3.3.5-dll64")
target_link_directories(${TargetName} PRIVATE "C:\\path\\to\\fftw-3.3.5-dll64")
target_link_libraries(${TargetName} PRIVATE libfftwf3-3)

After building this, the application was still not working. Eventually, I figured out that on opening the executable, windows was looking for the libfftw3-3 dll file. At the time I just wanted to get it working, so I copied the .dll files that are included with the library - even though this is shared/dynamic linking, not static linking.


I'm now trying to properly statically link the library; I removed the dll's from my build folder and filtered my CMakeLists.txt file down to:

add_executable(${TargetName} PRIVATE main.cpp)
target_include_directories(${TargetName} PRIVATE "C:\\path\\to\\fftw-3.3.5-dll64")
target_link_libraries(${TargetName} PRIVATE libfftwf3-3)

This builds, as I would expect it would. However, even though, in my CMakeLists.txt file, I've taken the steps to statically link the library, I'm still required to copy the dll's over in order for the executable to run (its dynamically linking still).


(Successful) verbose build output: https://pastebin.com/bbrZdd7r

2
Can you show the output of the verbose link command? - Kevin
@squareskittles i dont know what you mean - Tobi Akinyemi
When you compile the executable, there will be typically be some logs printed. It would be helpful to include these in your question post. What is your compiler? There should be a way to show a more verbose compilation/linkage output so that this log prints additional information that will be helpful to solve the issue. - Kevin
@squareskittles MSVC 1926 (using ninja). I'll add the build output (it passes) - Tobi Akinyemi
To get the verbose linker output, you might try running ninja -v to provide additional verbosity. This will show which library is actually being linked. - Kevin

2 Answers

3
votes

The LIB files you generated from the DEF files are "stubs". They contain just enough code to load the DLL and call functions from it. They do not contain the actual FFTW code. You cannot statically link with these pre-built FFTW LIBs.

You will need to compile FFTW into a static library yourself first. It comes with a CMake build file where you can turn off BUILD_SHARED_LIBS.

edit: on review, your question is nearly identical to this one, with the same answer.

1
votes

libs can be either static or dynamic. The one's generated (following the instructions in the README-WINDOWS file) are shared (they link to the .dll files inside the same folder.

With the windows binaries provided by FFTW, you cannot statically link (because all they provide are the dynamic libraries (.dlls). If you look at the file size of the .lib file, it's very small, because it's just a reference to the .dlls.

Follow the instructions on FFTW's windows page, for building the library from the source. Because you're now building the library yourself, you have the option to turn of "shared-library" and make a "static" lib.