NanoMichael / MicroTeX

A dynamic, cross-platform, and embeddable LaTeX rendering library
MIT License
418 stars 69 forks source link

fix error LNK2001: unresolved external symbol #76

Closed PikachuHy closed 3 years ago

PikachuHy commented 3 years ago

This a dirty PR to fix https://github.com/NanoMichael/cLaTeXMath/pull/73#issuecomment-842803855

I am very confused that all functions are implemented in the cpp file, but MSVC still reports errors.

error LNK2001: unresolved external symbol

When I move the code to the header(.h) file, the problem disappeared.

Maybe I can find better way to solve this bug later.

PikachuHy commented 3 years ago

uh, no

NanoMichael commented 3 years ago

That is really weird... Unfortunately, I don't have a Windows PC on my hand, so I can't reproduce these errors. But I've noticed that the header file fonts/font_basic.h has not been included in the file src/atom/atom_char.cpp and the file src/fonts/font_info.cpp, maybe these errors are related to it.

May you try to add the following line into the file src/atom/atom_char.cpp and the file src/fonts/font_info.cpp and check if it can solve this issue?

#include "fonts/font_basic.h"
PikachuHy commented 3 years ago

not work. in fonts/font_info.cpp, the header file fonts/font_basic.h is included by fonts/font_info.h, and in atom/atom_char.cpp, the header file fonts/font_basic.h is included by res/parser/formula_parser.h

PikachuHy commented 3 years ago
LINK Pass 1: command "C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1428~1.299\bin\Hostx64\x64\link.exe /nologo CMakeFiles\LaTeXQtSample.dir\LaTeXQtSample_autogen\mocs_compilation.cpp.obj CMakeFiles\LaTeXQtSample.dir\src\samples\qt_texwidget.cpp.obj CMakeFiles\LaTeXQtSample.dir\src\samples\qt_mainwindow.cpp.obj CMakeFiles\LaTeXQtSample.dir\src\samples\qt_main.cpp.obj /out:LaTeX.exe /implib:LaTeX.lib /pdb:LaTeX.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console C:\Qt\6.0.0\msvc2019_64\lib\Qt6Widgetsd.lib LaTeX.lib C:\Qt\6.0.0\msvc2019_64\lib\Qt6Guid.lib C:\Qt\6.0.0\msvc2019_64\lib\Qt6Cored.lib mpr.lib userenv.lib d3d11.lib dxgi.lib dxguid.lib C:\app\vcpkg\installed\x64-windows\debug\lib\tinyxml2d.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\LaTeXQtSample.dir/intermediate.manifest CMakeFiles\LaTeXQtSample.dir/manifest.res" failed (exit code 1120) with the following output:
LaTeX.lib(render.cpp.obj) : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class tex::CharFont> __cdecl tex::FontInfo::getNextLarger(wchar_t)const " (?getNextLarger@FontInfo@tex@@QEBA?AV?$shared_ptr@VCharFont@tex@@@std@@_W@Z) referenced in function "public: virtual bool __cdecl tex::DefaultTeXFont::hasNextLarger(class tex::Char const &)" (?hasNextLarger@DefaultTeXFont@tex@@UEAA_NAEBVChar@2@@Z)
LaTeX.lib(fonts.cpp.obj) : error LNK2001: unresolved external symbol "public: class std::shared_ptr<class tex::CharFont> __cdecl tex::FontInfo::getNextLarger(wchar_t)const " (?getNextLarger@FontInfo@tex@@QEBA?AV?$shared_ptr@VCharFont@tex@@@std@@_W@Z)
LaTeX.lib(fonts.cpp.obj) : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class tex::CharFont> __cdecl tex::FontInfo::getLigture(wchar_t,wchar_t)const " (?getLigture@FontInfo@tex@@QEBA?AV?$shared_ptr@VCharFont@tex@@@std@@_W0@Z) referenced in function "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::DefaultTeXFont::getLigature(struct tex::CharFont const &,struct tex::CharFont const &)" (?getLigature@DefaultTeXFont@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEBUCharFont@2@0@Z)
LaTeX.lib(macro_def.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::SymbolAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@SymbolAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.lib(macro_def.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::CharAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@CharAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.lib(parser.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::CharAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@CharAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.lib(atom_basic.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::CharAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@CharAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.lib(macro_def.cpp.obj) : error LNK2019: unresolved external symbol "public: __cdecl tex::CharBox::CharBox(struct tex::Char const &)" (??0CharBox@tex@@QEAA@AEBUChar@1@@Z) referenced in function "public: virtual class std::shared_ptr<class tex::Box> __cdecl tex::CedillaAtom::createBox(class tex::Environment &)" (?createBox@CedillaAtom@tex@@UEAA?AV?$shared_ptr@VBox@tex@@@std@@AEAVEnvironment@2@@Z)
LaTeX.lib(atom_basic.cpp.obj) : error LNK2001: unresolved external symbol "public: __cdecl tex::CharBox::CharBox(struct tex::Char const &)" (??0CharBox@tex@@QEAA@AEBUChar@1@@Z)
LaTeX.lib(atom_row.cpp.obj) : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class tex::CharFont> __cdecl tex::FixedCharAtom::getCharFont(class tex::TeXFont &)" (?getCharFont@FixedCharAtom@tex@@UEAA?AV?$shared_ptr@VCharFont@tex@@@std@@AEAVTeXFont@2@@Z)
LaTeX.exe : fatal error LNK1120: 6 unresolved externals
ninja: build stopped: subcommand failed.
NanoMichael commented 3 years ago

I've been reproduced these errors and try to solve them, it is really weird...

NanoMichael commented 3 years ago

Unfortunately, I don't have any clue to solve these issues except your solution... 😅 I believe it's a bug in the MSVC linker. I suggest adding some comments to show these are really 'dirty' solutions.