Hi,
I had bad performance with https://github.com/webview/webview and the nim binding https://github.com/oskca/webview compare to the other binding. (i tried rust and C and both were pretty fast)
Then I tried to upgrade the nim webview package to master. But now, I'm unable to compile.
I keep getting that error about atomic.h:
/Users/francisl/workspace/apps/webview/webview/webview.h:128:10: #include <atomic>
fatal error: ^~~~~~~~
'atomic' file not found
#include <atomic>
^~~~~~~~
In file included from /Users/francisl/.cache/nim/expensenim_r/stdlib_tables.nim.c:11:
/Users/francisl/workspace/apps/webview/webview/webview.h:128:10: fatal error: 'atomic' file not found
#include <atomic>
^~~~~~~~
If I try to pass the same argument I pass to my C program, (as documented on their github readme), I have the following error:
nim c --c:gcc --passC:-std=c++11 --passC:-stdlib=libc++ src/expensenim.nim
Error: execution of an external compiler program 'gcc -c -w -DWEBVIEW_STATIC -DWEBVIEW_IMPLEMENTATION -I/Users/francisl/workspace/apps/webview/webview -DWEBVIEW_COCOA=1 -x objective-c -std=c++11 -stdlib=libc++ -I/usr/local/Cellar/nim/1.2.6/nim/lib -I/Users/francisl/workspace/fl/expensenim/src -o /Users/francisl/.cache/nim/expensenim_d/stdlib_dollars.nim.c.o /Users/francisl/.cache/nim/expensenim_d/stdlib_dollars.nim.c' failed with exit code: 1
error: invalid argument '-std=c++11' not allowed with 'Objective-C'
error: invalid argument '-std=c++11' not allowed with 'Objective-C'
errorerror: : invalidinvaliderror : argumentargument '-std=c++11''-std=c++11' invalidnotnot argumentallowedallowed with '-std=c++11'with errorerror : : 'Objective-C'not invalidinvalid
'Objective-C' allowedargumentargument with
'-std=c++11''-std=c++11' 'Objective-C'notnot
I'm a bit clueless about a possible solution. So if anyone has an idea and help me progress solving that issue, it would be greatly appreciated.
Thanks
Yes I know it has changed. and I don't mind spending a bit of time learning and fixing it if possible.
The reason I ask the question, I think that specific error is not from the change specifically but on how nim compiles.
Using the same compiler(?) on the same machine, I can get the C version compiled and running without any issues. But it requires to pass the c++11 parameter.
Is it because we need the c++ compiler for the C source?
here is the command I run to compile the C example:
g++ main.c -std=c++11 -framework WebKit -o webview-example
It's because webview.nim has
{.passC: "-DWEBVIEW_COCOA=1 -x objective-c".}
{.passL: "-framework Cocoa -framework WebKit".}
for osx First step to get a new and exciting error message is to replace that with
{.passC:"-framework WebKit".}
and compile with nim cpp I don't think you need std=c++11 because nim cpp already uses std=gnu++14 but it doesn't hurt this works for me on linux with latest webview.h
#webview.nim
when defined(linux):
{.passC:"`pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0`".}
{.passL:"`pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0`".}
elif defined(windows):#NOT TESTED
{.passC:"-mwindows".}
{.passL:"-L./dll/x64 -lwebview -lWebView2Loader".}
elif defined(macosx):#NOT TESTED
{.passL: "-framework WebKit".}
type
Webview* {.header:"webview.h",importc:"webview_t".} = pointer
WebviewHint* = enum
WEBVIEW_HINT_NONE,WEBVIEW_HINT_MIN,WEBVIEW_HINT_MAX,WEBVIEW_HINT_FIXED
proc create*(debug:cint,window:pointer):Webview{.importc:"webview_create",header:"webview.h".}
proc set_title*(w:Webview,title:cstring){.importc:"webview_set_title",header:"webview.h".}
proc set_size*(w:Webview,width:cint,height:cint,hints:WebviewHint){.importc:"webview_set_size",header:"webview.h".}
proc navigate*(w:Webview,url:cstring){.importc:"webview_navigate",header:"webview.h".}
proc run*(w:Webview){.importc:"webview_run",header:"webview.h".}
proc destroy*(w:Webview){.importc:"webview_destroy",header:"webview.h".}
#minimal.nim
import webview
var w = create(0,nil)
w.set_title("Webview Nim Example")
w.set_size(480,320,WEBVIEW_HINT_NONE)
w.navigate("https://en.m.wikipedia.org/wiki/Main_Page")
w.run()
w.destroy()
compile with nim cpp minimal.nim
Perfect, thats more than I ask for, but at least I learn much.
Thank you
I changed my target in the nimble file to backend = "cpp"
and now I can compile and run it. Performance issue is resolved! :party:
Not sure why I need cpp and not c. but anyway.
Not sure why I need cpp and not c. but anyway.
It's because webview.h is C++ only now
Maybe I'm better to open a new question, But now all seem to work fine on Mac. here is my working fork https://github.com/francisl/webview
But now I can't build on windows. I got
fatal error: winrt/Windows.Foundation.Collections.h: No such file or directory
... #include <winrt/Windows.Foundation.Collections.h>
... ^
... compilation terminated.
does nim on windows with mingw can use the winrt libs?