Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem installing Webview for Crystal on Windows : WebView2.h: No such file or directory #20

Open
serge-hulne opened this issue Feb 8, 2023 · 21 comments

Comments

@serge-hulne
Copy link

Installing webview (0.2.1)
Postinstall of webview: make
Failed postinstall of webview on make:
make[1]: Entering directory 'C:/Users/serge/Documents/vue-tests/vue-tests-nomodules/crystapp/lib/webview'
g++ -c -o ext/webview.o -std=c++11 ext/webview.cc
make[1]: Leaving directory 'C:/Users/serge/Documents/vue-tests/vue-tests-nomodules/crystapp/lib/webview'
In file included from ext/webview.cc:2:
ext/webview.h:1047:10: fatal error: WebView2.h: No such file or directory
 1047 | #include "WebView2.h"
      |          ^~~~~~~~~~~~
compilation terminated.
make[1]: *** [Makefile:23: ext/webview.o] Error 1
make: *** [makefile:6: init] Error 1
@naqvis
Copy link
Owner

naqvis commented Feb 8, 2023

You need to have WebView2 SDK installed for compilation to work on windows.

This shard is just a wrapper against webview library, so if you encounter webview compilation related issues, please refer to webview library link.

@serge-hulne
Copy link
Author

Thank you.

@konovod
Copy link
Contributor

konovod commented Feb 10, 2023

I think with #21 this can be closed. @serge-hulne, can you confirm that it works?

@serge-hulne
Copy link
Author

serge-hulne commented Feb 10, 2023

I don't know. I couldn't make the WebView shard work under Windows (but maybe it's just me or maybe Crystal for Windows is still too experimental at this stage).
I initially wanted to port my rudimentary prototype from Mac OS to Windows (https://github.com/serge-hulne/CrystApp) but none of the required shards seem to work "out of the box" at this stage, so maybe I will just drop the idea to port it to Windows at this early stage of development of Crystal for Windows.

Feel free to close the issue.
Thanks for your kind help!

@serge-hulne
Copy link
Author

serge-hulne commented Feb 10, 2023

What would really help for my project is if a simple shards install (from the powershell or from a MSYS2 terminal) was sufficient to use WebView from Crystal under Windows 10/11 (the way it works on Mac OS, basically).

@serge-hulne
Copy link
Author

Here is how a V-Lang developper has done it. He uses scripts to build the libraries. There is no special tool needed (no requirement to use Microsoft Visual Code or so)

https://github.com/malisipi/mui/tree/main/webview

@konovod
Copy link
Contributor

konovod commented Feb 11, 2023

@serge-hulne have you checked updated section https://github.com/naqvis/webview#pre-requisite ?
No special tools is needed, just few commands.

Of course, one of the ways could be duplicate build.bat functionality from webview library in shard.yml postinstall. Both approaches has positive and negative sides.

Another problem (and maybe another issue) though is support of fibers. Basically, without periodical call of Fiber.yield or sleep(0.01) all fibers in current thread will stop working after calling Webview.run. The fact that it seems to work on Mac OS is coincidence - without Fiber.yield you will meet a frozen fibers in sufficiently big application (unless you completely avoid spawn).
I've patched original webview to have a callback in application loop, but it is simple only for Windows. Carbon and GTK implementations need another approach.

@serge-hulne
Copy link
Author

Hi, I haven't checked the updated section yet, but I will keep you posted as soon as I have.

Thank you!

@serge-hulne
Copy link
Author

serge-hulne commented Feb 11, 2023

I tried the installation procedure from your new documentation.

The first step worked:

   [x]  You should have Visual C++ Build tools already as it's a pre-requisite for crystal compiler
   [x]  git clone https://github.com/webview/webview to get WebView sources
   [x] webview\script\build.bat to compile them (it will download required nuget package)
   [x] copy webview\dll\x64\webview.lib to <your crystal installation>\lib
   [x] copy webview\dll\x64\webview.dll to directory with your program

The second step did't work:

  [x]   Add the dependency to your shard.yml:

    dependencies:
      webview:
        github: naqvis/webview

   [] Run shards install  <=== PROBLEM (See herunder)

The problem is that Visual C++ Build tools doesn't seem to install gcc or g++ on the command line, therefore when shards install tries to compile :

Resolving dependencies
Fetching https://github.com/naqvis/webview.git
Installing webview (0.2.2)
Postinstall of webview: make
Failed postinstall of webview on make:
g++ -c -o ext/webview.o -std=c++11 ext/webview.cc
process_begin: CreateProcess(NULL, uname, ...) failed.
Makefile:1: pipe: No error
process_begin: CreateProcess(NULL, g++ -c -o ext/webview.o -std=c++11 ext/webview.cc, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [Makefile:23: ext/webview.o] Error 2
PS C:\Users\serge\Documents\vue-tests\vue-tests-nomodules\webview6\app>

Screenshot (254)
Screenshot (255)

@konovod
Copy link
Contributor

konovod commented Feb 11, 2023

actually yes, shard.yml has to be fixed. but if directory lib/webview is present, you can try examples even though the step was failed.

@serge-hulne
Copy link
Author

serge-hulne commented Feb 11, 2023

Apparently not, since:

  • To try the examples, you have to compile the Crystal code examples.
  • To compile those you need to require "webview"
  • To do that, you need a shard install script which runs successfully.

I wish I could do more to help, but I have no experience with the gcc toolchain under Windows (I use MingW to fake a Unix development environment)

@konovod
Copy link
Contributor

konovod commented Feb 11, 2023

compilation was complete at previous steps. Mingw isn't needed as webview.dll is all need besides crystal code.
in my experiments the step fails bit the directory lib/webviewwas created, so require works. If the directory isn't present though, sone more actions needed.

@serge-hulne
Copy link
Author

If shards install fails, I'm stuck...

@naqvis
Copy link
Owner

naqvis commented Feb 12, 2023

Problem you are encountering is due to postinstall hook of shard.yml. And you can easily ignore that step by passing --skip-postinstall flag to shards install.

shards install --skip-postinstall

@serge-hulne
Copy link
Author

serge-hulne commented Feb 12, 2023

OK. That worked.

However, I got the following error when trying to build the app:

crystal build src/app.cr .\lib\webview.lib

In lib\webview.lib:1:2

 1 | !<arch>
      ^
Error: unexpected token: "<"

@konovod
Copy link
Contributor

konovod commented Feb 13, 2023

You have to do crystal build src/app.cr, lib files cannot be passed to crystal compiler directly.

@serge-hulne
Copy link
Author

I am sorry, it doesn't seem to work:

PS C:\Users\serge\Documents\vue-tests\vue-tests-nomodules\webview6\app> shards install --skip-postinstall
Resolving dependencies
Fetching https://github.com/naqvis/webview.git
Using webview (0.2.2)
PS C:\Users\serge\Documents\vue-tests\vue-tests-nomodules\webview6\app> crystal build .\src\app.cr
LINK : fatal error LNK1181: cannot open input file 'webview.lib'

@konovod
Copy link
Contributor

konovod commented Feb 13, 2023

have you copied webview.lib on a previous step (copy webview\dll\x64\webview.lib to <your crystal installation>\lib)?

@serge-hulne
Copy link
Author

serge-hulne commented Feb 13, 2023 via email

@serge-hulne
Copy link
Author

serge-hulne commented Feb 14, 2023

It works now, but the correct linking instruction (under Windows) for lib.cr seems to be:

@[Link(ldflags: "#{__DIR__}/webview.lib")]

With this instruction, webview.lib is expected to reside along the code of the app (in ./src in our example)

instead of:

@[Link("webview")]

@serge-hulne
Copy link
Author

serge-hulne commented Feb 17, 2023

I guess, in order to use @[Link("webview")] ( rather than @[Link(ldflags: "#{__DIR__}/webview.lib")] ), webview.lib is supposed to be installed in some standard locations for libraries under Windows 10 or 11 (the equivalent of /usr/local/lib under Linux).

However, in my case, running the install.bat script from https://github.com/webview/webview/tree/master/script did build said library webview.lib locally, but did apparently not copy it to a (standard)location which would be accessible by default to Crystal via a simple @[Link("webview")] , this is basically why the shards install fails and why I had to resort to the alternative : @[Link(ldflags: "#{__DIR__}/webview.lib")] for Crystal to be able to access Webview.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants