NanoMichael / MicroTeX

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

Unresolved external symbol -- How to use the library ? #127

Closed jokteur closed 2 years ago

jokteur commented 2 years ago

Hello,

I discovered this library because I want to include LaTeX equations in my app (I am using Dear ImGui as my GUI library). I looked into the samples to get inspiration. I figured out that I need to implement my own derived classes Font , TextLayout and Graphics2D in graphic.h. So I generated some empty classes that basically do nothing but that are still implemented (like in win32_main.cpp).

However, if I call just LaTex::init() in my main, the application does not link. I get: LaTeX.lib(box_single.obj) : error LNK2019: unresolved external symbol "public: static class std::shared_ptr<class tex::TextLayout> __cdecl tex::TextLayout::create(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &,class std::shared_ptr<class tex::Font> const &)" (?create@TextLayout@tex@@SA?AV?$shared_ptr@VTextLayout@tex@@@std@@AEBV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@4@AEBV?$shared_ptr@VFont@tex@@@4@@Z) referenced in function "private: void __cdecl tex::TextRenderingBox::init(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &,int,float,class std::shared_ptr<class tex::Font> const &,bool)" (?init@TextRenderingBox@tex@@AEAAXAEBV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@HMAEBV?$shared_ptr@VFont@tex@@@4@_N@Z) I kind of understand the issue: the linker is trying to find implementations of Font , TextLayout and Graphics2D but can't because they are abstract classes.

So, my basic question is: what is the minimal code I need to write to get MicroTeX compiling and embedded into a C++ application ? I don't really care about functionnality (I will implement the different draw calls one by one)

Here are some informations:

Thank you for your help

sp1ritCS commented 2 years ago

try building the openmath branch. AFIAK msvc is unable to export it's symbols into the shared object file and you need to explicitly tag every function you want exported. The code in the openmath branch should do this.

but thats just a guess of mine, I don't use msvc

NanoMichael commented 2 years ago

As sp1ritCS mentioned above, the master branch does not export symbols into the shared object file, and this branch is not under-maintained now. You could try the openmath branch, if you find any problem feel free to file issues.

PS. the openmath is not stable by now (the API may change) and has not been released yet anyway.

jokteur commented 2 years ago

I upgraded my MinGW distribution (there was a bug with GCC 8.1 and <filesystem>), and I managed to compile on the openmath branch.

try building the openmath branch. AFIAK msvc is unable to export it's symbols into the shared object file and you need to explicitly tag every function you want exported. The code in the openmath branch should do this.

but thats just a guess of mine, I don't use msvc

I suppose you are right. I changed to the openmath branch, and I get (with MSVC):

[build] graphic_imgui.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl microtex::Font_imgui::~Font_imgui(void)" (__imp_??1Font_imgui@microtex@@UEAA@XZ) referenced in function "public: virtual void * __cdecl microtex::Font_imgui::`scalar deleting destructor'(unsigned int)" (??_GFont_imgui@microtex@@UEAAPEAXI@Z) [path...]
[build] graphic_imgui.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl microtex::TextLayout_imgui::~TextLayout_imgui(void)" (__imp_??1TextLayout_imgui@microtex@@UEAA@XZ) referenced in function "public: virtual void * __cdecl microtex::TextLayout_imgui::`scalar deleting destructor'(unsigned int)" (??_GTextLayout_imgui@microtex@@UEAAPEAXI@Z) [path...]
[build] graphic_imgui.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) const microtex::Font_imgui::`vftable'" (__imp_??_7Font_imgui@microtex@@6B@) referenced in function "public: __cdecl microtex::Font_imgui::Font_imgui(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int,float)" (??0Font_imgui@microtex@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HM@Z) [path...]
[build] graphic_imgui.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) const microtex::TextLayout_imgui::`vftable'" (__imp_??_7TextLayout_imgui@microtex@@6B@) referenced in function "public: __cdecl microtex::TextLayout_imgui::TextLayout_imgui(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,enum microtex::FontStyle,float)" (??0TextLayout_imgui@microtex@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@W4FontStyle@1@M@Z) [path...]
[build] graphic_imgui.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) const microtex::Graphics2D_imgui::`vftable'" (__imp_??_7Graphics2D_imgui@microtex@@6B@) referenced in function "public: __cdecl microtex::Graphics2D_imgui::Graphics2D_imgui(void)" (??0Graphics2D_imgui@microtex@@QEAA@XZ) [path...]
[build] main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl microtex::PlatformFactory_imgui::PlatformFactory_imgui(void)" (__imp_??0PlatformFactory_imgui@microtex@@QEAA@XZ) referenced in function "class std::unique_ptr<class microtex::PlatformFactory_imgui,struct std::default_delete<class microtex::PlatformFactory_imgui> > __cdecl std::make_unique<class microtex::PlatformFactory_imgui,0>(void)" (??$make_unique@VPlatformFactory_imgui@microtex@@$$V$0A@@std@@YA?AV?$unique_ptr@VPlatformFactory_imgui@microtex@@U?$default_delete@VPlatformFactory_imgui@microtex@@@std@@@0@XZ) [path...]
[build] main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl microtex::PlatformFactory_imgui::~PlatformFactory_imgui(void)" (__imp_??1PlatformFactory_imgui@microtex@@UEAA@XZ) referenced in function "public: virtual void * __cdecl microtex::PlatformFactory_imgui::`scalar deleting destructor'(unsigned int)" (??_GPlatformFactory_imgui@microtex@@UEAAPEAXI@Z) 

Now that I have a working MinGW distribution, I suppose I will stay on MinGW for now.

NanoMichael commented 2 years ago

Seems you need to add MICROTEX_EXPORT to export your imgui implementations on MSVC.

jokteur commented 2 years ago

I did put MICROTEX_EXPORT in front of every class, but I need also to put in front of the functions, is that right ?

sp1ritCS commented 2 years ago

shouldn't it be __declspec(dllexport) to expose symbols on msvc? Why does it run with __declspec(dllimport)?

NanoMichael commented 2 years ago

How do you build your imgui implementations? Take platform/gdi_win/CMakeLists.txt as an example:

target_compile_definitions(microtex-gdi PRIVATE -DMICROTEX_LIBRARY)

Only when the flag MICROTEX_LIBRARY was defined the MICROTEX_EXPORT expands to __declspec(dllexport), otherwise it will expands to __declspec(dllimport), please check out the file lib/microtexexport.h.

sp1ritCS commented 2 years ago

btw, @NanoMichael

PS. the openmath is not stable by now (the API may change) and has not been released yet anyway.

is there any eta for when you are ready to release microtex/openmath (given that outside your flutter thing not much is happening)? it looks like notekit will release under a 0.2 version "soonish" and I've wondered if we could ship with microtex instead of clatexmath already.

NanoMichael commented 2 years ago

is there any eta for when you are ready to release microtex/openmath

Before October I guess 😂 (mainly because I do not have much time on this project).

sp1ritCS commented 2 years ago

is there any eta for when you are ready to release microtex/openmath

Before October I guess :joy: (mainly because I do not have much time on this project).

sure, you have any todo list on what's missing?

NanoMichael commented 2 years ago

sure, you have any todo list on what's missing?