I've been trying to create a wrapper for Zaitsev's Webview library (https://github.com/webview/webview) - I know there is already one, but it's pretty much abandoned and obsolete (as it doesn't support the new version of the library which has undergone more than a few changes).
Currently, the test repo is here: https://github.com/drkameleon/nim-webview
And I'm compiling with nim c --nimcache:.cache test.nim
However, I keep getting linker errors, e.g:
Undefined symbols for architecture x86_64:
"_webview_create", referenced from:
_NimMainModule in @mtest.nim.c.o
"_webview_destroy", referenced from:
_NimMainModule in @mtest.nim.c.o
"_webview_navigate", referenced from:
_NimMainModule in @mtest.nim.c.o
"_webview_run", referenced from:
_NimMainModule in @mtest.nim.c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of an external program failed: 'clang -o /Users/drkameleon/Documents/Code/OpenSource/nim-webview/test /Users/drkameleon/Documents/Code/OpenSource/nim-webview/.cache/webview.cc.o /Users/drkameleon/Documents/Code/OpenSource/nim-webview/.cache/stdlib_digitsutils.nim.c.o /Users/drkameleon/Documents/Code/OpenSource/nim-webview/.cache/stdlib_dollars.nim.c.o /Users/drkameleon/Documents/Code/OpenSource/nim-webview/.cache/stdlib_system.nim.c.o /Users/drkameleon/Documents/Code/OpenSource/nim-webview/.cache/@mtest.nim.c.o -lstdc++ -framework WebKit -ldl'
Any idea what is going on (or anybody more experienced than me with creating wrappers)?
NOTE: The core point of this whole experiment is not the wrapper itself but to use the library from a compiled-to-C Nim project. Thus, anything like nim cpp is out of the question.
Looks like compiling webview.cc by itself (gcc -c -std=c++11 webview.cc) and then linking it via Nim (like {.passL: "-L. -lwebview.o -lstdc++ -framework WebKit".}) does work.
Hmm...
All of that being said, I think I've managed to fix the issues I had.
Anybody that want to try it (especially on Linux, or Windows - where I have no access), I would be glad to hear what you think.
P.S. I'm obviously in the process of wrapping up the remaining methods - so let's call this a work-in-progress, but I believe I'm pretty much close to it. :)
That's an awesome question. I have no idea! haha
I've never been an extreme fan of OOP, but decided to experiment with it a bit - for the first time with Nim - as it seemed like a natural choice. But I'd easily be 2 clicks away from reconsidering lol
I also created some updated webview lib - not sure if I updated the branch for webview 2 https://github.com/marcomq/webview However - I think the webview/webview library itself is pretty dead and nearly unusable in its latest version. Most important window and message features are missing and there are major issues to open a local html file. The old c versions were usable but unfortunately didn't support edge on windows.
Nearly all previous webview devs are working on Tauri or wry - which both actually look very good but don't have a c interface yet.
As far as I know, they just decided to unbloat the codebase of the official webview/webview repo (and thus removed all non purely webview-related functionality.
Regarding Windows & Linking that's exactly what I've been struggling with since yesterday.
Basically, I've set up different CI workflows (macOS, Linux & Windows), and it's Windows as usual the one that bugs me the most. I've managed to solve different issues, now here's where I'm stuck (obviously, this cl that doesn't accept gcc style arguments for the linking stage, so I'm trying to figure out how to do it):
cl : Command line warning D9002 : ignoring unknown option '-lstdc++'
cl : Command line warning D9002 : ignoring unknown option '-mwindows'
cl : Command line warning D9002 : ignoring unknown option '-L./dll/x64'
cl : Command line warning D9002 : ignoring unknown option '-lwebview'
cl : Command line warning D9002 : ignoring unknown option '-lWebView2Loader'
webview.cc.obj : error LNK2019: unresolved external symbol CreateCoreWebView2EnvironmentWithOptions referenced in function "public: virtual bool __cdecl webview::edge_chromium::embed(struct HWND__ *,bool,class std::function<void __cdecl(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)>)" (?embed@edge_chromium@webview@@UEAA_NPEAUHWND__@@_NV?$function@$$A6AXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z@std@@@Z)
D:\a\nim-webview\nim-webview\test.exe : fatal error LNK1120: 1 unresolved externals
Error: execution of an external program failed: 'vccexe.exe --platform:amd64 /FeD:\a\nim-webview\nim-webview\test.exe C:\Users\runneradmin\nimcache\test_d\webview.cc.obj C:\Users\runneradmin\nimcache\test_d\stdlib_digitsutils.nim.c.obj C:\Users\runneradmin\nimcache\test_d\stdlib_dollars.nim.c.obj C:\Users\runneradmin\nimcache\test_d\stdlib_io.nim.c.obj C:\Users\runneradmin\nimcache\test_d\stdlib_system.nim.c.obj C:\Users\runneradmin\nimcache\test_d\@mwebview.nim.c.obj C:\Users\runneradmin\nimcache\test_d\@mtest.nim.c.obj /nologo -lstdc++ -mwindows -L./dll/x64 -lwebview -lWebView2Loader '
Anybody who knows more about how this thing could work on Windows is more than welcome to help! :)
Here's the workflow (Windows) in question: https://github.com/drkameleon/nim-webview/blob/main/.github/workflows/windows.yml#L39-L66
Still some progress made, but I cannot get it to compile for Windows no matter what.
Nim Compiler Version 1.6.4 [Windows: amd64]
Compiled at 2022-02-09
Copyright (c) 2006-2021 by Andreas Rumpf
active boot switches: -d:release
Hint: used config file 'D:\a\nim-webview\nim-webview\nim\nim-1.6.4\config\nim.cfg' [Conf]
Hint: used config file 'D:\a\nim-webview\nim-webview\nim\nim-1.6.4\config\config.nims' [Conf]
..........................................................
D:\a\nim-webview\nim-webview\webview.nim(85, 8) Warning: use {.base.} for base methods; baseless methods are deprecated [UseBase]
D:\a\nim-webview\nim-webview\webview.nim(63, 6) Hint: 'webview_get_window' is declared but not used [XDeclaredButNotUsed]
webview.cc
stdlib_digitsutils.nim.c
stdlib_dollars.nim.c
stdlib_io.nim.c
stdlib_system.nim.c
@mwebview.nim.c
@mtest.nim.c
CC: webview
CC: stdlib_digitsutils.nim
CC: stdlib_dollars.nim
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: webview.nim
CC: test.nim
Hint: [Link]
cl : Command line warning D9002 : ignoring unknown option '-lstdc++'
cl : Command line warning D9024 : unrecognized source file type 'dll\x64\WebView2Loader.dll', object file assumed
dll\x64\WebView2Loader.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2E8
Error: execution of an external program failed: 'vccexe.exe --platform:amd64 /FeD:\a\nim-webview\nim-webview\test.exe C:\Users\runneradmin\nimcache\test_d\webview.cc.obj C:\Users\runneradmin\nimcache\test_d\stdlib_digitsutils.nim.c.obj C:\Users\runneradmin\nimcache\test_d\stdlib_dollars.nim.c.obj C:\Users\runneradmin\nimcache\test_d\stdlib_io.nim.c.obj C:\Users\runneradmin\nimcache\test_d\stdlib_system.nim.c.obj C:\Users\runneradmin\nimcache\test_d\@mwebview.nim.c.obj C:\Users\runneradmin\nimcache\test_d\@mtest.nim.c.obj /nologo -lstdc++ /EHsc /std:c++17 "dll\x64\WebView2Loader.dll"
Can somebody shed some light? Am I doing something wrong related to Nim?
cl : Command line warning D9002 : ignoring unknown option '-lstdc++'
means vcc doesn't understand the options of gcc. You need to find the -l equivalent on vcc.
cl : Command line warning D9024 : unrecognized source file type 'dll\x64\WebView2Loader.dll', object file assumed
dll\x64\WebView2Loader.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2E8
means it tried to link the dll as a .obj but failed.
The solution may be:
when not defined(vcc):
discard #The -l equivalent
else:
{.passL: "-lWebView2Loader".}
Thanks a lot for the point.
You are right.
I have already fixed this part - and I've almost managed to get it to compile.
Now, I'm struggling with the possibility of eliminating the need for an extra DLL (meaning, to fully link all needed library in a static way).
If I make it, I'll let you all know. The thing is it looks very promising. :)
Great work there.
I wish I had found it before I started my own take on the subject - funny thing is we ended up with something very similar haha.
Have a great day! :)