nlfiedler / magick-rust

Rust bindings for ImageMagick
https://crates.io/crates/magick_rust
Apache License 2.0
259 stars 68 forks source link

Having trouble building it on Windows #115

Closed dolsem closed 11 months ago

dolsem commented 11 months ago

I followed installation instructions and when I try to build the library I get:

Unable to find libclang: "couldn't find any valid shared libraries matching: ['clang.dll', 'libclang.dll'], set the LIBCLANG_PATH environment variable to a path where one of these files can be found (invalid: [])"

So I tried setting LIBCLANG_PATH to the lib folder inside the folder LLVM gets installed to. Now when I build I get:

imagemagick\include\MagickWand/MagickWand.h:59:10: fatal error: 'stdio.h' file not found

Any idea how to fix it?

nlfiedler commented 11 months ago

I gave it a try this morning and didn't have an issue with building, but running the tests failed because the executable couldn't find the MagickWand .dll file. For my setup, I have LIBCLANG_PATH pointing to the bin directory of the LLVM installation (C:\Program Files\LLVM\bin), rather than the lib folder. For the IMAGE_MAGICK_DIR setting, it should point to the ImageMagick install directory (C:\Program Files\MagickWand-7.1.1-Q16-HDRI). That, and the Microsoft build tools, should be all that is necessary for building the library.

dolsem commented 11 months ago

@nlfiedler I just tried pointing to the bin directory and it still doesn't work... Says it cannot find 'stdio.h'. I definitely have Microsoft build tools installed, per the instructions. I am on Windows 11. Is it possible that you have something else installed on the machine you're testing on, or perhaps an environment variable I don't have?

dolsem commented 11 months ago

I fixed it. I am using Visual Studio Code and I was missing things in my environment. I ended up creating buildenv.bat file in the project directory with the following contents:

@echo off
set IMAGE_MAGICK_DIR=%cd%\imagemagick
call C:\"Program Files"\"Microsoft Visual Studio"\2022\Community\VC\Auxiliary\Build\vcvars64.bat

Then I added .vscode/settings.json with the following:

{
  "terminal.integrated.profiles.windows": {
    "MSVC": {
      "path": "cmd",
      "args": ["/K", "buildenv.bat"]
    }
  },
  "terminal.integrated.defaultProfile.windows": "MSVC",
}

Now I can just run cargo build in VS Code terminal and it builds fine.

nlfiedler commented 11 months ago

Here are all of my environment variables:

ALLUSERSPROFILE                C:\ProgramData
APPDATA                        C:\Users\nlfie\AppData\Roaming
ChocolateyInstall              C:\ProgramData\chocolatey
ChocolateyLastPathUpdate       133399689864016405
ChocolateyToolsLocation        C:\tools
CommonProgramFiles             C:\Program Files\Common Files
CommonProgramFiles(x86)        C:\Program Files (x86)\Common Files
CommonProgramW6432             C:\Program Files\Common Files
COMPUTERNAME                   LAPTOP-KMJO106G
ComSpec                        C:\WINDOWS\system32\cmd.exe
DriverData                     C:\Windows\System32\Drivers\DriverData
HOMEDRIVE                      C:
HOMEPATH                       \Users\nlfie
IMAGE_MAGICK_DIR               C:\Program Files\ImageMagick-7.1.1-Q16-HDRI
LIBCLANG_PATH                  C:\Program Files\LLVM\bin
LOCALAPPDATA                   C:\Users\nlfie\AppData\Local
LOGONSERVER                    \\LAPTOP-KMJO106G
NUMBER_OF_PROCESSORS           16
OneDrive                       C:\Users\nlfie\OneDrive
OneDriveConsumer               C:\Users\nlfie\OneDrive
OPENSSL_DIR                    C:\Users\nlfie\Downloads\vcpkg\installed\x64-windows
OS                             Windows_NT
Path                           C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPo...
PATHEXT                        .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL
POWERSHELL_DISTRIBUTION_CHA... MSI:Windows 10 Home
PROCESSOR_ARCHITECTURE         AMD64
PROCESSOR_IDENTIFIER           Intel64 Family 6 Model 141 Stepping 1, GenuineIntel
PROCESSOR_LEVEL                6
PROCESSOR_REVISION             8d01
ProgramData                    C:\ProgramData
ProgramFiles                   C:\Program Files
ProgramFiles(x86)              C:\Program Files (x86)
ProgramW6432                   C:\Program Files
PSModulePath                   C:\Users\nlfie\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell...
PUBLIC                         C:\Users\Public
SESSIONNAME                    Console
SystemDrive                    C:
SystemRoot                     C:\WINDOWS
TEMP                           C:\Users\nlfie\AppData\Local\Temp
TMP                            C:\Users\nlfie\AppData\Local\Temp
USERDOMAIN                     LAPTOP-KMJO106G
USERDOMAIN_ROAMINGPROFILE      LAPTOP-KMJO106G
USERNAME                       nlfie
USERPROFILE                    C:\Users\nlfie
windir                         C:\WINDOWS
WSLENV                         WT_SESSION:WT_PROFILE_ID:
WT_PROFILE_ID                  {61c54bbd-c2c6-5271-96e7-009a87ff44bf}
WT_SESSION                     da192d7a-8666-4d61-be7a-9195bf6c43da
ZES_ENABLE_SYSMAN              1

Adding ImageMagick to the PATH fixed the STATUS_DLL_NOT_FOUND error I was getting when running the tests.

Here are all of the directories where a stdio.h file exists:

C:\Microsoft\AndroidNDK\android-ndk-r23c\sources\cxx-stl\llvm-libc++\include
C:\Microsoft\AndroidNDK\android-ndk-r23c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include
C:\Microsoft\AndroidNDK\android-ndk-r23c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\bits\fortify
C:\Microsoft\AndroidNDK\android-ndk-r23c\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\c++\v1
C:\Program Files (x86)\Windows Kits\10\Include\10.0.20348.0\ucrt
C:\Users\nlfie\.cargo\registry\src\index.crates.io-6f17d22bba15001f\libssh2-sys-0.3.0\libssh2\os400\include

I suspect the Windows Kits one is the one that matters -- I had installed MSVC back before upgrading the system to Windows 11, but it will works fine.