LNK2019 error while using pffft in Qt Creator

41 views Asked by At

I'm making an app with the Qt framework using Qt Creator and CMake (not qmake, because I want the full project to be buildable from other IDEs, but that's not relevant for this topic). In this project, I need the pffft library which is a compact and convenient alternative of fftw. This library has a .h header, and a .c file for the implementation. But when I try to build the project and run it, I get the LNK2019 error for EVERY function I use from this library, although I added the .h and .c files in the CMakeLists.txt, and included the .h file in every source file that uses it (checked that around 10 times now haha) Note : everything worked fine before implementing pffft, so I'm pretty sure it's this library that creates the problem.

Here is the part of my CMakeLists.txt where I tell CMake to compile all the files I need (the .ico and .png files are also in the list I know, this file is automatically generated by Qt so I don't touch it that much) :

set(PROJECT_SOURCES
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(IR_Maker
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
        pffft.c pffft.h
        about.h about.cpp about.ui
        add.qrc
        img/irmaker.ico
        sweepgenerator.h sweepgenerator.cpp sweepgenerator.ui
        img/branch-closed2.png img/branch-open2.png
        qcustomplot.cpp qcustomplot.h
    )

Finally, my config is :

  • Windows 10
  • Qt 6.6.2
  • Qt Creator 12.0.1
  • MSVC 2019 compiler

Since the pffft library has a .c source file and not a .cpp, I modified the project(IR_Maker VERSION 0.1 LANGUAGES CXX) to project(IR_Maker VERSION 0.1 LANGUAGES CXX C), and the LNK2019 errors disappreared but I have a "C1189 error : Error in C++ Standrad Library usage" in a .h file inside of the compiler directory, so I don't know if that gets me any closer from a solution. Same thing happends if I simply remove the LANGUAGES CXX in the project() arguments.

I also changed the compiler from MSVC 2019 to MinGW because I heard about pffft not being msvc friendly (or the opposite haha), and the errors also disappeared but now it's another problem where it doesn't find my qcustomplot.h file in the autogenerated .h file made from the .ui file of the mainwindow (where qcustomplot.h is used), even if I have the qcustomplot.h file in my project directory.

I checked for the extern "C" command in the .h file, and it is as shows this code. I'm not sure about the ordrer of the rest so it'll maybe be useful.

#ifndef PFFFT_H
#define PFFFT_H

#include <stddef.h> // for size_t

#ifdef __cplusplus
extern "C" {
#endif
// all the header contents are there
#ifdef __cplusplus
}
#endif

#endif // PFFFT_H

Here is the full body of the compile output when I want to build & run the project :

12:30:04: Running steps for project IR_Maker...
12:30:04: Starting: "C:\_PROG\C++\_CMAKE\bin\cmake.exe" --build C:/_PROG/C++/QtApps/IR_Maker/build/debug-msvc2019-64bit --target all
-- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: C:/_PROG/C++/QtApps/IR_Maker/build/debug-msvc2019-64bit
[0/1 0.0/sec] Re-running CMake...
[1/6 7.6/sec] Automatic MOC and UIC for target IR_Maker
[2/5 1.5/sec] Building CXX object CMakeFiles\IR_Maker.dir\about.cpp.obj
[3/5 1.9/sec] Building CXX object CMakeFiles\IR_Maker.dir\sweepgenerator.cpp.obj
[4/5 0.8/sec] Building CXX object CMakeFiles\IR_Maker.dir\mainwindow.cpp.obj
[5/5 1.0/sec] Linking CXX executable IR_Maker.exe
FAILED: IR_Maker.exe 
C:\Windows\system32\cmd.exe /C "cd . && C:\_PROG\C++\_CMAKE\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\IR_Maker.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\MSVC\1439~1.335\bin\Hostx64\x64\link.exe /nologo CMakeFiles\IR_Maker.dir\IR_Maker_autogen\mocs_compilation.cpp.obj CMakeFiles\IR_Maker.dir\main.cpp.obj CMakeFiles\IR_Maker.dir\mainwindow.cpp.obj CMakeFiles\IR_Maker.dir\about.cpp.obj CMakeFiles\IR_Maker.dir\sweepgenerator.cpp.obj CMakeFiles\IR_Maker.dir\qcustomplot.cpp.obj CMakeFiles\IR_Maker.dir\IR_Maker_autogen\EWIEGA46WW\qrc_add.cpp.obj  /out:IR_Maker.exe /implib:IR_Maker.lib /pdb:IR_Maker.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:windows  C:\Qt\6.6.2\msvc2019_64\lib\Qt6PrintSupportd.lib  C:\Qt\6.6.2\msvc2019_64\lib\Qt6Widgetsd.lib  C:\Qt\6.6.2\msvc2019_64\lib\Qt6Guid.lib  C:\Qt\6.6.2\msvc2019_64\lib\Qt6Cored.lib  mpr.lib  userenv.lib  C:\Qt\6.6.2\msvc2019_64\lib\Qt6EntryPointd.lib  shell32.lib  d3d11.lib  dxgi.lib  dxguid.lib  d3d12.lib  comdlg32.lib  winspool.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK Pass 1: command "C:\PROGRA~1\MIB055~1\2022\COMMUN~1\VC\Tools\MSVC\1439~1.335\bin\Hostx64\x64\link.exe /nologo CMakeFiles\IR_Maker.dir\IR_Maker_autogen\mocs_compilation.cpp.obj CMakeFiles\IR_Maker.dir\main.cpp.obj CMakeFiles\IR_Maker.dir\mainwindow.cpp.obj CMakeFiles\IR_Maker.dir\about.cpp.obj CMakeFiles\IR_Maker.dir\sweepgenerator.cpp.obj CMakeFiles\IR_Maker.dir\qcustomplot.cpp.obj CMakeFiles\IR_Maker.dir\IR_Maker_autogen\EWIEGA46WW\qrc_add.cpp.obj /out:IR_Maker.exe /implib:IR_Maker.lib /pdb:IR_Maker.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:windows C:\Qt\6.6.2\msvc2019_64\lib\Qt6PrintSupportd.lib C:\Qt\6.6.2\msvc2019_64\lib\Qt6Widgetsd.lib C:\Qt\6.6.2\msvc2019_64\lib\Qt6Guid.lib C:\Qt\6.6.2\msvc2019_64\lib\Qt6Cored.lib mpr.lib userenv.lib C:\Qt\6.6.2\msvc2019_64\lib\Qt6EntryPointd.lib shell32.lib d3d11.lib dxgi.lib dxguid.lib d3d12.lib comdlg32.lib winspool.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\IR_Maker.dir/intermediate.manifest CMakeFiles\IR_Maker.dir/manifest.res" failed (exit code 1120) with the following output:
mainwindow.cpp.obj : error LNK2019: unresolved external symbol pffft_new_setup referenced in function "private: void __cdecl MainWindow::on_createir_button_clicked(void)" (?on_createir_button_clicked@MainWindow@@AEAAXXZ)
mainwindow.cpp.obj : error LNK2019: unresolved external symbol pffft_destroy_setup referenced in function "private: void __cdecl MainWindow::on_createir_button_clicked(void)" (?on_createir_button_clicked@MainWindow@@AEAAXXZ)
mainwindow.cpp.obj : error LNK2019: unresolved external symbol pffft_transform referenced in function "private: void __cdecl MainWindow::on_createir_button_clicked(void)" (?on_createir_button_clicked@MainWindow@@AEAAXXZ)
mainwindow.cpp.obj : error LNK2019: unresolved external symbol pffft_zconvolve_accumulate referenced in function "private: void __cdecl MainWindow::on_createir_button_clicked(void)" (?on_createir_button_clicked@MainWindow@@AEAAXXZ)
mainwindow.cpp.obj : error LNK2019: unresolved external symbol pffft_aligned_malloc referenced in function "private: void __cdecl MainWindow::on_createir_button_clicked(void)" (?on_createir_button_clicked@MainWindow@@AEAAXXZ)
mainwindow.cpp.obj : error LNK2019: unresolved external symbol pffft_aligned_free referenced in function "private: void __cdecl MainWindow::on_createir_button_clicked(void)" (?on_createir_button_clicked@MainWindow@@AEAAXXZ)
IR_Maker.exe : fatal error LNK1120: 6 unresolved externals
ninja: build stopped: subcommand failed.
12:30:09: The process "C:\_PROG\C++\_CMAKE\bin\cmake.exe" exited with code 1.
Error while building/deploying project IR_Maker (kit: Desktop Qt 6.6.2 MSVC2019 64bit)
When executing step "Build"
12:30:09: Elapsed time: 00:06.
0

There are 0 answers