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

Installation and execution of NetVips #3

Closed
roganjoshua opened this issue May 2, 2018 · 16 comments
Closed

Installation and execution of NetVips #3

roganjoshua opened this issue May 2, 2018 · 16 comments
Labels
question Further information is requested

Comments

@roganjoshua
Copy link

Hi I am trying to get netvips working here on windows.Will this work?

Do I need to set up Environment Variables first?

I get this

ibvips zip file not in download directory. Downloading now ...
Downloading file: https://github.com/jcupitt/libvips/releases/download/v/vips-.zip

which of course fails

All the tests fail.

Not sure where to put the downloaded vips folder?

System.TypeInitializationException : The type initializer for '' threw an exception.
[02/05/2018 13:30:36 Informational] [xUnit.net 00:00:01.3574786] ---- System.DllNotFoundException : Unable to load DLL 'libvips-42.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
[02/05/2018 13:30:36 Informational] [xUnit.net 00:00:01.3575698] Stack Trace:
[02/05/2018 13:30:36 Informational] [xUnit.net 00:00:01.3576566] at NetVips.Tests.TestsFixture..ctor()
[02/05/2018 13:30:36 Informational] [xUnit.net 00:00:01.3577459] ----- Inner Stack Trace -----
[02/05/2018 13:30:36 Informational] [xUnit.net 00:00:01.3578316] at NetVips.Internal.Vips.VipsInit(String argv0)
[02/05/2018 13:30:36 Informational] [xUnit.net 00:00:01.3579297] C:\Users\Martin_Sarosi\Downloads\net-vips-master\src\NetVips\ModuleInitializer.cs(13,0): at NetVips.ModuleInitializer.Initialize()
[02/05/2018 13:30:36 Informational] [xUnit.net 00:00:01.3580023] at .cctor()

Any help

@kleisauke
Copy link
Owner

Hello @roganjoshua,

It looks like you tried to run .\build.ps1. When running the Cake Build script a few environment needs to be set first. It should work like this in PowerShell:

$env:VIPS_VERSION = "8.6.3"
$env:VIPS_ZIP_VERSION = "dev-w64-all-8.6.3-1"
$env:VIPS_HOME = "C:\vips-dev-$env:VIPS_VERSION"
$env:PATH = "$env:VIPS_HOME\bin;$env:PATH"
.\build.ps1

However, the Cake Build script is only used for the continuous integration builds, so it's not needed to run it. When you want to use NetVips in your project(s) I can recommend installing it with NuGet. In the NuGet Package Manager Console it can be installed like this:

Install-Package NetVips

You'll only need the libvips shared library on your library search path, see for more info:
https://jcupitt.github.io/libvips/install.html#installing-the-windows-binary

@kleisauke kleisauke added the question Further information is requested label May 2, 2018
@roganjoshua
Copy link
Author

Thanks for such a quick reply. My problem is finding the vips dlls.

On windows what is the library search path?

I don't where to put it for the tests to run.

Apologies for my idiocy.

NetVips.Tests.ArithmeticTests.TestAbs [FAIL]
[03/05/2018 07:32:04 Informational] [xUnit.net 00:00:01.0535451] System.TypeInitializationException : The type initializer for '' threw an exception.
[03/05/2018 07:32:04 Informational] [xUnit.net 00:00:01.0538460] ---- System.DllNotFoundException : Unable to load DLL 'libvips-42.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
[03/05/2018 07:32:04 Informational] [xUnit.net 00:00:01.0553459] Stack Trace:
[03/05/2018 07:32:04 Informational] [xUnit.net 00:00:01.0571805] at NetVips.Tests.TestsFixture

@roganjoshua
Copy link
Author

I copied them into Test bin\debug folder and now get

System.TypeInitializationException : The type initializer for '' threw an exception.
[03/05/2018 07:50:21 Informational] [xUnit.net 00:00:00.8170957] ---- System.BadImageFormatException : An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
[03/05/2018 07:50:21 Informational] [xUnit.net 00:00:00.8181482] Stack Trace:

@kleisauke
Copy link
Owner

kleisauke commented May 3, 2018

You don't need to copy libvips in the bin\debug directory. Just make sure that the environment variable PATH is set correctly. I've written a step-by-step plan:

For Windows:

  1. Download vips-dev-w64-web-x.y.z.zip from the download area of libvips. The last one is vips-dev-w64-web-8.6.3-1.zip at the time of writing.
  2. Unzip vips-dev-w64-web-x.y.z.zip to a suitable location that can easily be remembered. For example: C:\vips-dev-8.6.3.
  3. Add the bin (e.g. C:\vips-dev-8.6.3\bin) directory to your PATH environment variable:
    1. In Search, search for SystemPropertiesAdvanced and then select it.
    2. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit.
    3. In the Edit System Variable window, click the New button, which will add a line at the end of the list. Add the libvips bin directory (C:\vips-dev-8.6.3\bin in our example) and hit Enter. Click OK. Close all remaining windows by clicking OK.
  4. Now libvips would have been installed successfully, reopen Visual Studio or the Command prompt window (to ensure that the environment is updated), and run your code that has references to NetVips.

Let me know if something is unclear.

@RyanYANG52
Copy link

I think 'TypeInitializationException' is because you are using 32bit, and libvips bin is win64, mine works fine. Just use x64 instead of AnyCpu @roganjoshua

@kleisauke
Copy link
Owner

Ah, I overlooked the BadImageFormatException, the recommendation from @RyanYANG52 should work in that case.

@jcupitt
Copy link
Contributor

jcupitt commented May 8, 2018

The libvips binary vips-dev-w64-all-x.y.z.zip contains ALL the file format loaders that libvips supports, including some very minor ones, and a complete copy of ImageMagick. It can process many different file types, but it is also rather vulnerable to hacking. I'm sure it would be easy to exploit with crafted input files.

The vips-dev-w64-web-x.y.z.zip build contains only file format loaders that have been carefully tested and which are commonly used on the web. It won't load formats like openslide (for example), but it should be much safer to use with untrusted input images.

@NiteshSaxena
Copy link

@RyanYANG52 , Many thanks, saved the day!.

@kleisauke
Copy link
Owner

I've been thinking whether there is a better solution to prevent users from downloading the libvips binaries and the need to set their PATH environment variable to find the required DLL's on Windows.

I could set-up the NuGet package to bundle the latest pre-compiled libvips binaries (this can be done through making a runtimes folder which has sub-folders named {platform}-{architecture}\lib\native). Magick.NET solves the problem from setting the PATH environment and the need to download the ImageMagick binary in that way.

Unfortunately there a disadvantages to this approach:

  • Users are unable to choose a different version of libvips because the libvips binary files are included in the NuGet package.
  • Maintaining NetVips becomes more difficult because for every libvips release, NetVips also needs to be updated (I now only need to update NetVips if there are API changes in libvips).

The advantage of this approach is that users can install NetVips easier without the need to set-up libvips first.

I weigh the pros and cons and I think we have to stick to the current installation / packaging behavior. Only on Windows it's slightly more difficult to install. On MacOS libvips is on Homebrew, MacPorts and Fink. On Linux it's in included in the package manager (for example Debian, Ubuntu, CentOS, RHEL, Fedora, Alpine, SuSE, FreeBSD, etc. have libvips in their package manager).

For Windows, I think vcpkg can help with this in the future, see these open issues:
https://github.com/jcupitt/libvips/issues/868
microsoft/vcpkg#2676

@kleisauke kleisauke changed the title Help! Installation and execution of NetVips May 10, 2018
@jcupitt
Copy link
Contributor

jcupitt commented May 10, 2018

Yes, a NuGet package that installed libvips would be useful. Could NetVips depend on it and have it pulled in automatically?

@kleisauke
Copy link
Owner

I've packed the latest Windows libvips web binary (vips-dev-w64-web-8.6.3-1) with 3f90491. It's following this approach: https://stackoverflow.com/a/40652794/1480019. So all the libvips binaries will be copied to the project's output directory. The only thing that looks not so neat is that 48 files are being copied, I could try to ILMerge those dependencies into one.

It's semi-automatic, for packaging / publishing only a few variables needs to be set (in PowerShell).

$env:VIPS_VERSION = "8.6.3"
$env:VIPS_ZIP_VERSION = "dev-w64-web-8.6.3-1"
$env:VIPS_HOME = "C:\vips-dev-$env:VIPS_VERSION"
$env:PATH = "$env:VIPS_HOME\bin;$env:PATH"
.\build.ps1 --target=Pack

If someone want to test this, use the nightly version of NetVips. Add the https://ci.appveyor.com/nuget/net-vips feed in the <packageSources> section of your NuGet.config:

<packageSources>
  <add key="netvips-nightly" value="https://ci.appveyor.com/nuget/net-vips" />
</packageSources>

And update NetVips to 1.0.2.69.

@jcupitt Is it maybe possible to merge all dependencies (except GLib and GObject) into one DLL in build-win64? That will also solve the problem with wrong versions of DLL's being included, like this issue what I had a while ago.

@kleisauke
Copy link
Owner

Merged to master. I will try to make a new release within a few days.

Making one DLL of libvips would be ideal, but I'm not sure how difficult this is. I'll investigate whether it is possible to do this in https://github.com/jcupitt/build-win64.

@jcupitt
Copy link
Contributor

jcupitt commented May 11, 2018

Could a merged DLL be a licence violation? The LGPL says users need to be able to replace shared libraries, and libvips has a lot of LGPL dependencies.

@kleisauke
Copy link
Owner

I've created libvips/build-win64#21 in order to keep this issue clean.

@kleisauke
Copy link
Owner

I've just released version 1.0.3 on NuGet. The pre-compiled libvips Windows binary is bundled with this version. It's therefore no longer necessary to download the pre-compiled binary and to set the PATH environment variable.

The readme has some remarks about how to disable the bundled libvips and use a different version of libvips.

I'm sorry it took so long, I had some busy weeks on my university. I'll close this issue for now, please feel free to re-open if there's still a problem.

kleisauke added a commit that referenced this issue Jun 28, 2018
Add solutions for common exceptions. See #3 and #8.
@JPomichael
Copy link

I think 'TypeInitializationException' is because you are using 32bit, and libvips bin is win64, mine works fine. Just use x64 instead of AnyCpu @roganjoshua

wow. successed. thx

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

No branches or pull requests

6 participants