QtExcel / QXlsx

Excel file(*.xlsx) reader/writer library using Qt 5 or 6. Descendant of QtXlsxWriter.
https://qtexcel.github.io/QXlsx/
MIT License
1.16k stars 358 forks source link

Cannot link when compile Qxlsx with CMake #134

Closed Phymin closed 2 years ago

Phymin commented 3 years ago

Hello,

Thanks for providing this great library for us. But when I use it with cmake, I encountered a link problem. I copy the source file from QXlsx directory and write my own CMakeLists.txt file, the compile and generation of QXlsx static library is fine. But when I link to the static library with the example code from Hello world example, I got the following link error

FAILED: examples/demo2.exe 
cmd.exe /C "cd . && "D:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=examples\CMakeFiles\demo2.dir --rc=D:\WINDOW~1\10\bin\100177~1.0\x64\rc.exe --mt=D:\WINDOW~1\10\bin\100177~1.0\x64\mt.exe --manifests  -- "D:\Program Files (x86)\MICROS~1\2017\ENTERP~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe" /nologo examples\CMakeFiles\demo2.dir\demo2_autogen\mocs_compilation.cpp.obj examples\CMakeFiles\demo2.dir\Demo2.cpp.obj  /out:examples\demo2.exe /implib:examples\demo2.lib /pdb:examples\demo2.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console  PXlsx.lib  D:\Qt\Qt5.14.2\5.14.2\msvc2017_64\lib\Qt5Guid.lib  D:\Qt\Qt5.14.2\5.14.2\msvc2017_64\lib\Qt5Cored.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cmd.exe /C "cd /D E:\VSTSProject\build-QtXlsx-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug\examples && C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass -file D:/dev/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary E:/VSTSProject/build-QtXlsx-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug/examples/demo2.exe -installedDir D:/dev/vcpkg/installed/x64-windows/debug/bin -OutVariable out""
LINK Pass 1: command "D:\Program Files (x86)\MICROS~1\2017\ENTERP~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo examples\CMakeFiles\demo2.dir\demo2_autogen\mocs_compilation.cpp.obj examples\CMakeFiles\demo2.dir\Demo2.cpp.obj /out:examples\demo2.exe /implib:examples\demo2.lib /pdb:examples\demo2.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console PXlsx.lib D:\Qt\Qt5.14.2\5.14.2\msvc2017_64\lib\Qt5Guid.lib D:\Qt\Qt5.14.2\5.14.2\msvc2017_64\lib\Qt5Cored.lib kernel32.lib user32.lib gdi32.lib winspool.lib
shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:examples\CMakeFiles\demo2.dir/intermediate.manifest examples\CMakeFiles\demo2.dir/manifest.res" failed (exit code 1120) with the following output:
PXlsx.lib(xlsxdocument.cpp.obj) : error LNK2001: Unresolved external symbol "public: virtual struct QMetaObject const * __cdecl QXlsx::Document::metaObject(void)const " (?metaObject@Document@QXlsx@@UEBAPEBUQMetaObject@@XZ)
PXlsx.lib(xlsxdocument.cpp.obj) : error LNK2001: Unresolved external symbol "public: virtual void * __cdecl QXlsx::Document::qt_metacast(char const *)" (?qt_metacast@Document@QXlsx@@UEAAPEAXPEBD@Z)
PXlsx.lib(xlsxdocument.cpp.obj) : error LNK2001: Unresolved external symbol "public: virtual int __cdecl QXlsx::Document::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Document@QXlsx@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
examples\demo2.exe : fatal error LNK1120: 3 unresolved external commands
ninja: build stopped: subcommand failed.

I have tried to solve this problem for about 2 hours and I failed, I also tried with qmake with the "how to setup QXlsx project" guide and this try works. So I'd like to know where the problem is with CMake? I Use QtCreator(Qt5.14.2) with CMake and VS2017 x64 compiler.

j2doll commented 3 years ago

How about using qmake(.pro;.pri) instead of cmake? I'm not sure exactly because cmake file is not made by me.

Phymin commented 3 years ago

Hi, thanks for you reply, the qmake setup is fine, but not with CMake.

j2doll commented 3 years ago

Thanks for reporting. I will register this issue to an error.

xakod commented 3 years ago

Hello, i have some troubles with cmake + ninja + msvc 2019x64 But on ubuntu 21.04 with cmake + Unix Makefiles + gcc everything ok

[1/36 3.1/sec] Automatic MOC for target QXlsx
[2/36 1.0/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdatetype.cpp.obj
[3/36 1.4/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcellrange.cpp.obj
[4/36 1.8/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcelllocation.cpp.obj
[5/36 2.2/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxabstractsheet.cpp.obj
[6/36 2.6/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcellreference.cpp.obj
[7/36 3.0/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdocpropsapp.cpp.obj
[8/36 3.4/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcellformula.cpp.obj
[9/36 3.8/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcontenttypes.cpp.obj
[10/36 3.9/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcell.cpp.obj
[11/36 4.0/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxabstractooxmlfile.cpp.obj
[12/36 4.3/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcolor.cpp.obj
[13/36 4.4/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdatavalidation.cpp.obj
[14/36 4.7/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxchartsheet.cpp.obj
[15/36 3.9/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx_autogen\mocs_compilation.cpp.obj
[16/36 4.1/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxchart.cpp.obj
[17/36 4.3/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdocpropscore.cpp.obj
[18/36 4.1/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxconditionalformatting.cpp.obj
[19/36 3.9/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxnumformatparser.cpp.obj
[20/36 4.1/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxrelationships.cpp.obj
[21/36 4.2/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdrawing.cpp.obj
[22/36 4.4/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxsimpleooxmlfile.cpp.obj
[23/36 4.6/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxmediafile.cpp.obj
[24/36 4.7/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxformat.cpp.obj
[25/36 4.8/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxtheme.cpp.obj
[26/36 5.0/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdocument.cpp.obj
[27/36 5.1/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxsharedstrings.cpp.obj
[28/36 5.1/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxutility.cpp.obj
[29/36 5.2/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdrawinganchor.cpp.obj
[30/36 5.2/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxrichstring.cpp.obj
[31/36 5.2/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxworkbook.cpp.obj
[32/36 5.3/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxzipreader.cpp.obj
[33/36 5.4/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxzipwriter.cpp.obj
[34/36 5.4/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxstyles.cpp.obj
[35/36 5.0/sec] Building CXX object CMakeFiles\QXlsx.dir\QXlsx\source\xlsxworksheet.cpp.obj
[36/36 4.9/sec] Linking CXX shared library QXlsx.dll
FAILED: QXlsx.dll QXlsx.lib 
cmd.exe /C "cmd.exe /C ""C:\Program Files\CMake\bin\cmake.exe" -E __create_def C:\Users\aao\source\repos\coma-cmake\include\build-QXlsx-Desktop_Qt_5_15_2_MSVC2019_64bit-Release\CMakeFiles\QXlsx.dir\.\exports.def C:\Users\aao\source\repos\coma-cmake\include\build-QXlsx-Desktop_Qt_5_15_2_MSVC2019_64bit-Release\CMakeFiles\QXlsx.dir\.\exports.def.objs && cd C:\Users\aao\source\repos\coma-cmake\include\build-QXlsx-Desktop_Qt_5_15_2_MSVC2019_64bit-Release" && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_dll --intdir=CMakeFiles\QXlsx.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100190~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MICROS~4\2019\COMMUN~1\VC\Tools\MSVC\1428~1.299\bin\Hostx64\x64\link.exe /nologo CMakeFiles\QXlsx.dir\QXlsx_autogen\mocs_compilation.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxabstractooxmlfile.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxabstractsheet.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcell.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcellformula.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcelllocation.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcellrange.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcellreference.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxchart.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxchartsheet.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcolor.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxconditionalformatting.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcontenttypes.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdatavalidation.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdatetype.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdocpropsapp.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdocpropscore.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdocument.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdrawing.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdrawinganchor.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxformat.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxmediafile.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxnumformatparser.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxrelationships.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxrichstring.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxsharedstrings.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxsimpleooxmlfile.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxstyles.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxtheme.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxutility.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxworkbook.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxworksheet.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxzipreader.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxzipwriter.cpp.obj  /out:QXlsx.dll /implib:QXlsx.lib /pdb:QXlsx.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO  /DEF:CMakeFiles\QXlsx.dir\.\exports.def  C:\Qt\5.15.2\msvc2019_64\lib\Qt5Gui.lib  C:\Qt\5.15.2\msvc2019_64\lib\Qt5Core.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib  && cd ."
LINK: command "C:\PROGRA~2\MICROS~4\2019\COMMUN~1\VC\Tools\MSVC\1428~1.299\bin\Hostx64\x64\link.exe /nologo CMakeFiles\QXlsx.dir\QXlsx_autogen\mocs_compilation.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxabstractooxmlfile.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxabstractsheet.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcell.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcellformula.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcelllocation.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcellrange.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcellreference.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxchart.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxchartsheet.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcolor.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxconditionalformatting.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxcontenttypes.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdatavalidation.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdatetype.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdocpropsapp.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdocpropscore.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdocument.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdrawing.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxdrawinganchor.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxformat.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxmediafile.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxnumformatparser.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxrelationships.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxrichstring.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxsharedstrings.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxsimpleooxmlfile.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxstyles.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxtheme.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxutility.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxworkbook.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxworksheet.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxzipreader.cpp.obj CMakeFiles\QXlsx.dir\QXlsx\source\xlsxzipwriter.cpp.obj /out:QXlsx.dll /implib:QXlsx.lib /pdb:QXlsx.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO /DEF:CMakeFiles\QXlsx.dir\.\exports.def C:\Qt\5.15.2\msvc2019_64\lib\Qt5Gui.lib C:\Qt\5.15.2\msvc2019_64\lib\Qt5Core.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:QXlsx.dll.manifest" failed (exit code 1120) with the following output:
   Creating library QXlsx.lib and object QXlsx.exp
xlsxchart.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class QTypedArrayData<class QXmlStreamAttribute>::const_iterator __cdecl QVector<class QXmlStreamAttribute>::begin(class QTypedArrayData<class QXmlStreamAttribute>::const_iterator)const " (__imp_?begin@?$QVector@VQXmlStreamAttribute@@@@QEBA?AVconst_iterator@?$QTypedArrayData@VQXmlStreamAttribute@@@@V23@@Z) referenced in function "protected: class QString __cdecl QXlsx::ChartPrivate::readSubTree(class QXmlStreamReader &)" (?readSubTree@ChartPrivate@QXlsx@@IEAA?AVQString@@AEAVQXmlStreamReader@@@Z)
xlsxworksheet.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class QTypedArrayData<class QXmlStreamAttribute>::const_iterator __cdecl QVector<class QXmlStreamAttribute>::begin(class QTypedArrayData<class QXmlStreamAttribute>::const_iterator)const " (__imp_?begin@?$QVector@VQXmlStreamAttribute@@@@QEBA?AVconst_iterator@?$QTypedArrayData@VQXmlStreamAttribute@@@@V23@@Z)
  Hint on symbols that are defined and could potentially match:
    "__declspec(dllimport) public: void * * __cdecl QListData::begin(void)const " (__imp_?begin@QListData@@QEBAPEAPEAXXZ)
    "__declspec(dllimport) public: class QChar const * __cdecl QString::begin(void)const " (__imp_?begin@QString@@QEBAPEBVQChar@@XZ)
    "__declspec(dllimport) public: class QTextBlock::iterator __cdecl QTextBlock::begin(void)const " (__imp_?begin@QTextBlock@@QEBA?AViterator@1@XZ)
xlsxchart.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class QTypedArrayData<class QXmlStreamAttribute>::const_iterator __cdecl QVector<class QXmlStreamAttribute>::end(class QTypedArrayData<class QXmlStreamAttribute>::const_iterator)const " (__imp_?end@?$QVector@VQXmlStreamAttribute@@@@QEBA?AVconst_iterator@?$QTypedArrayData@VQXmlStreamAttribute@@@@V23@@Z) referenced in function "protected: class QString __cdecl QXlsx::ChartPrivate::readSubTree(class QXmlStreamReader &)" (?readSubTree@ChartPrivate@QXlsx@@IEAA?AVQString@@AEAVQXmlStreamReader@@@Z)
xlsxworksheet.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class QTypedArrayData<class QXmlStreamAttribute>::const_iterator __cdecl QVector<class QXmlStreamAttribute>::end(class QTypedArrayData<class QXmlStreamAttribute>::const_iterator)const " (__imp_?end@?$QVector@VQXmlStreamAttribute@@@@QEBA?AVconst_iterator@?$QTypedArrayData@VQXmlStreamAttribute@@@@V23@@Z)
  Hint on symbols that are defined and could potentially match:
    "__declspec(dllimport) public: void * * __cdecl QListData::end(void)const " (__imp_?end@QListData@@QEBAPEAPEAXXZ)
    "__declspec(dllimport) public: class QChar const * __cdecl QString::end(void)const " (__imp_?end@QString@@QEBAPEBVQChar@@XZ)
QXlsx.dll : fatal error LNK1120: 2 unresolved externals
ninja: build stopped: subcommand failed.
18:58:19: Процесс «C:\Program Files\CMake\bin\cmake.exe» завершился с кодом 1.
Ошибка при сборке/развёртывании проекта QXlsx (комплект: Desktop Qt 5.15.2 MSVC2019 64bit)
Во время выполнения этапа «Сборка»
xakod commented 2 years ago

@dantti this issue can be closed

DarthGandalf commented 2 years ago

@Jihadist was it fixed?

xakod commented 2 years ago

@DarthGandalf it was fixed by #218

DarthGandalf commented 2 years ago

Fix confirmed.