StrawberryPerl / Perl-Dist-Strawberry

Tooling to build and package releases for Perl on Windows.
https://strawberryperl.com
Other
264 stars 48 forks source link

Build Image::Magick from MSYS2 using Strawberry Perl gcc and perl #139

Open hakonhagland opened 9 months ago

hakonhagland commented 9 months ago

Refer to #138 for background. I would like to try to build Image::Magick with Strawberry Perl. On Linux I can build the module using:

$ ./configure --with-perl=/home/hakon/perlbrew/perls/perl-5.38.0/bin/perl --prefix=/opt/image-magick
$ make
$ sudo make install

In #138 ït was suggested to use MSYS2, quote from @sysiphus:

IIUC, it should be pretty much the same with Strawberry Perl, but you'll be running the commands in the MSYS2 shell. I take it that the --with-perl argument designates which perl is to be used for the building of the ImageMagick library. So you could use MSYS2 perl for that - which might make it easier wrt the Cairo stuff that @shawnlaffan mentioned. You would want to ensure that, in the MSYS2 shell, gcc identifies StrawberryPerl's C compiler, so you might need to modify MSYS2's path for that,

Also @sysiphus reported later in that issue:

Eventually it terminates with: CC coders/MagickCore_libMagickCore_7_Q16HDRI_la-tiff.lo coders/tiff.c:109:13: fatal error: zstd.h: No such file or directory 109 | # include | ^~~~ compilation terminated. make[1]: [Makefile:10344: coders/MagickCore_libMagickCore_7_Q16HDRI_la-tiff.lo] Error 1 make[1]: Leaving directory '/d/s/ImageMagick' make: [Makefile:6243: all] Error 2

@sisyphus As a first step, I tried to reproduce the error you got. However, I got a different error:

$ /c/Strawberry/perl/bin/perl.exe --version This is perl 5, version 38, subversion 0 (v5.38.0) built for MSWin32-x64-multi-thread

- Modified PATH and ran configure and then make:

$ export PATH=/c/Strawberry/c/bin:$PATH

$ ./configure --with-perl=/c/Strawberry/perl/bin/perl.exe 2>&1 | tee configure_log.txt

$ make 2>&1 | tee make_log.txt [...] CC coders/MagickCore_libMagickCore_7_Q16HDRI_la-jpeg.lo CC filters/MagickCore_libMagickCore_7_Q16HDRI_la-analyze.lo CCLD MagickCore/libMagickCore-7.Q16HDRI.la C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: MagickCore\.libs\libMagickCore_7_Q16HDRI_la-blob.o: in function EOFBlob': C:\msys2\home\hakon\test\ImageMagick/MagickCore/blob.c:1270: undefined reference toBZ2_bzerror' C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: MagickCore\.libs\libMagickCore_7_Q16HDRI_la-blob.o: in function `ErrorBlob': [...] collect2.exe: error: ld returned 1 exit status make[1]: [makefile:7214: MagickCore/libMagickCore-7.Q16HDRI.la] Error 1 make[1]: Leaving directory 'C:/msys2/home/hakon/test/ImageMagick' make: [makefile:6243: all] Error 2


Here are the complete log files from configure and make: [configure_log.txt](https://github.com/StrawberryPerl/Perl-Dist-Strawberry/files/12820365/configure_log.txt) and [make_log.txt](https://github.com/StrawberryPerl/Perl-Dist-Strawberry/files/12820677/make_log.txt).
sisyphus commented 9 months ago

Why not just install ImageMagick into msys2/mingw64 and access that from Strawberry Perl to install Perl-Magick ?

You'd want to install the mingw64 package. In the MSYS2 shell:

$ pacman -S mingw64/mingw-w64-x86_64-imagemagick

That installs version 7.1.1.15-1 of ImageMagick for mingw64.

My msys2 installation is in D:\msys64. I've managed to build ImageMagick from github source by running:

./configure CPPFLAGS=-I/d/msys64/mingw64/include LDFLAGS=-L/d/msys64/mingw64/lib

If perl was involved in that build, then it would have been my msys2 perl (D:\msys64\usr\bin\perl).

I saw the same warnings as I reported earlier during the 'make' phase. Running 'make check' reports that 4 of the 87 test scripts returned 'FAIL'. Those 4 were:

FAIL: tests/cli-pipe.tap 13
FAIL: tests/cli-pipe.tap 14
FAIL: tests/cli-pipe.tap 15
PASS: tests/cli-pipe.tap 16
FAIL: tests/cli-pipe.tap 17

The compiler I used was: gcc.exe (MinGW-W64 x86_64-msvcrt-posix-seh, built by Brecht Sanders) 13.2.0

I meant to use the 13.1.0 version (which is the same as the one used by Strawberry) - but inadvertently added the 13.2.0 to the path by mistake. I doubt that matters much ... but it might be important that the compiler be run outside of Strawberry's clutches. I mean - it might be important that instead of adding your strawberry/c/bin to the path, you grab the very same compiler from winlibs, install it in a separate location, and add that location to the path. (Dunno if that makes any difference.) I'll do some more fiddling about as time permits.

Note that my build probably only worked because libzstd and a whole lot of other stuff had already been installed into the mingw64 section of my msys2 installation. You'll have to install those mingw64 packages as it becomes evident that they're needed.

Maybe start by having pacman install ImageMagick - which will hopefully install everything else you need to start building the ImageMagick source from github.

Cheers, Rob

sisyphus commented 9 months ago

In a fresh msys2 shell, with a fresh clone of the github ImageMagick source, I set the PATH:

$ export PATH=$PATH:/c/winpos-gcc-1310/mingw64/bin

I then ran:

$ ./configure CPPFLAGS=-I/d/msys64/mingw64/include LDFLAGS=-L/d/msys64/mingw64/lib --with-perl=/c/sp/_64/perl-5.38.0-PDL/c/perl.exe --prefix=/c/sp/_64/perl-5.38.0-PDL/c

Running 'make' then proceeded as per the previous build, until it reached the point where my previous build had reached completion:

  CXXLD    Magick++/lib/libMagick++-7.Q16HDRI.la
cp -f MagickCore/ImageMagick.pc MagickCore/ImageMagick-7.Q16HDRI.pc
cp -f MagickCore/MagickCore.pc MagickCore/MagickCore-7.Q16HDRI.pc
cp -f MagickWand/MagickWand.pc MagickWand/MagickWand-7.Q16HDRI.pc
cp -f Magick++/lib/Magick++.pc Magick++/lib/Magick++-7.Q16HDRI.pc
#### PREVIOUS BUILD SUCCESSFULLY FINISHED AT THIS POINT - sisyphus#####
  GEN      PerlMagick/quantum/Q16HDRI.xs
cp: cannot stat 'quantum.xs': No such file or directory
make[1]: *** [Makefile:13906: PerlMagick/quantum/Q16HDRI.xs] Error 1
make[1]: Leaving directory '/d/s/ImageMagick2'
make: *** [Makefile:6243: all] Error 2

I don't yet know what has caused that failure. @hakonhagland, are you sure we need to build ImageMagick --with-perl ?? Can't we just build and install ImageMagick, then build PerlMagick against that installed library ?

Cheers, Rob

shawnlaffan commented 9 months ago

It would seem the perl path is only needed to compile the perl bindings at the same time as the main ImageMagick system.

Compiling the bindings separately might be a simpler approach.

From https://imagemagick.org/script/advanced-linux-installation.php (with added linebreaks for readability):

--without-perl  disable build/install of PerlMagick, or

By default, PerlMagick is conveniently compiled and installed as part of 
ImageMagick's normal configure, make, sudo make install process. 
When --without-perl is specified, you must first  install ImageMagick, 
change to the PerlMagick subdirectory, build, and finally install PerlMagick. 
Note, PerlMagick is configured even if --without-perl is specified. 
If the argument --with-perl=/path/to/perl is supplied, 
/../path/to/perl is be taken as the PERL interpreter to use. 
This important in case the perl executable in your PATH is not PERL5, 
or is not the PERL you want to use.
sisyphus commented 9 months ago

Thanks for that @shawnlaffan. When I get a chance I'll try to build Perl-Magick separately on Strawberry Perl - against either the ImageMagick library that pacman installed or against the ImageMagick library I built from github source. That was obviously the way I did it, 7 years ago.

(I would actually be quite happy to see someone "beat me to it" ;-)

Cheers, Rob

hakonhagland commented 9 months ago

@hakonhagland, are you sure we need to build ImageMagick --with-perl ?? Can't we just build and install ImageMagick, then build PerlMagick against that installed library?

@sisyphus Maybe. Let me try this on Linux first

hakonhagland commented 9 months ago

Can't we just build and install ImageMagick, then build PerlMagick against that installed library?

Maybe. Let me try this on Linux first

@sisyphus It did not work for me on Linux, added bug report here: https://github.com/ImageMagick/ImageMagick/issues/6763

sisyphus commented 9 months ago

Yeah - same error for me. I've made the import libs locatable by setting $ENV{LIBRARY_PATH} appropriately:

set LIBRARY_PATH=D:\msys64\mingw64\lib

That took care of the "library not found" warning that perl Makefile.PL other wise emits. And, so that the headers get found, I've done:

> set CPATH=D:\msys64\mingw64\include;

(I won't find out if that's the correct setting for CPATH until some compilations are done. Perhaps it's necessary to specify the D:\msys64\mingw64\include\ImageMagick-7 directory.)

The Makefile.PL has some instructions specifically for Strawberry Perl, including:

# 1) You need to have installed ImageMagick Windows binaries from
#    https://imagemagick.org/script/binary-releases.php#windows

That's probably more in line with what I did last time I built PerlMagick. We could probably try that if we need to - the link seems to be providing current ImageMagick. (Something for the weekend perhaps.)

Cheers, Rob

hakonhagland commented 9 months ago

The Makefile.PL has some instructions specifically for Strawberry Perl, including:

# 1) You need to have installed ImageMagick Windows binaries from # https://imagemagick.org/script/binary-releases.php#windows

@sisyphus Interesting. I also found this site for building ImageMagick using Visual Studio on Windows:

https://github.com/ImageMagick/ImageMagick-Windows

It could be interesting to test, but not sure if it will help with building the Perl module

hakonhagland commented 9 months ago

$ ./configure --with-perl=/c/Strawberry/perl/bin/perl.exe 2>&1 | tee configure_log.txt

$ make 2>&1 | tee make_log.txt [...] C:\msys2\home\hakon\test\ImageMagick/MagickCore/blob.c:1270: undefined reference to `BZ2_bzerror'

@shawnlaffan I think this BZ2_bzerror should be defined in libzip2, right? Does Strawberry Perl include that library? If not, how can we add it?

shawnlaffan commented 9 months ago

@hakonhagland - SP provides it. Look for libbz2.

The version with SP5.38 is 1.06. It might need to be updated to 1.08 but I suspect not. (I forget why it is still at 1.06 given https://github.com/StrawberryPerl/build-extlibs/issues/28).

Another option is to try building without bzip2 support using the --without-bzlib config arg (or perhaps --with-bzlib=no). Ideally the build would include bzip2 support, but this approach will at least get past that error for now.

sisyphus commented 9 months ago

I've had success on StrawberryPerl 5.38.0-PDL, building Perl-Magick (Image-Magick-7.1) against the mingw64 ImageMagick library that MSYS2 installs. My MSYS2 installation is in D:\msys64. Having used pacman to install ImageMagick in D:\msys\mingw64, I opened up a new shell running Strawberry (portable) 5.38.0-PDL and did the following:

cd to the Image-Magick-7.1 source folder - obtained from unpacking https://imagemagick.org/archive/perl/Image-Magick-7.1.1-18.tar.gz

set PATH=%PATH%;D:\msys64\mingw64\bin (put ImageMagick dlls in path)

set CPATH=%CPATH%;D:\msys64\mingw64\include;D:\msys64\mingw64\include\ImageMagick-7 (for required ImageMagick header files - and any other msys2 header files that might be needed.)

set LIBRARY_PATH=D:\msys64\mingw64\lib (for required ImageMagick libraries - and any other msys2 libraries that might be needed)

Copy D:\msys64\mingw64\lib\libMagickCore-7.Q16HDRI.dll.a to D:\msys64\mingw64\lib\libMagickCore.dll.a (because that's the name of the import library that the build of the perl module looks for).

Then run perl Makefile.PL, gmake test and gmake install.

I could perhaps have built against the ImageMagick library I built from github source ... I'll try that out when I get a chance.

Cheers, Rob

hakonhagland commented 9 months ago

Does Strawberry Perl include that library? SP provides it. Look for libbz2.

@shawnlaffan Yes I can see that it is there. So then the problem is not that the library is missing, rather I think the problem is that PATH is not correct.. That is, it is missing /c/Strawberry/c/bin even if I did this:

export PATH=/c/Strawberry/c/bin:$PATH

before running configure. By investigating the generated Makefile I see a line like this is executed:

C:/msys2/usr/bin/sh.exe ./libtool --verbose --tag=CC   --mode=link gcc  -fopenmp -Wall -g [...]

My guess is that when Makefile is running C:/msys2/usr/bin/sh.exe the modified PATH is reset to some default value within this new shell, and the linker cannot find libbz2.dll inside the /c/Strawberry/c/bin folder.

hakonhagland commented 9 months ago

the modified PATH is reset to some default value within this new shell

Added a discussion for how to pass the updated PATH to the libtool shell here:

https://github.com/ImageMagick/ImageMagick/discussions/6766

sisyphus commented 9 months ago

I could perhaps have built against the ImageMagick library I built from github source

That almost works. It fails only because some warnings produced when building Image-Magick-7.1.1 against the MSYS2 installation of ImageMagick-7.1.1-15, turn into fatal errors when building against the ImageMagick library that was built from github source.

That is, the warnings: D:\msys64\mingw64\include\ImageMagick-7/MagickCore/magick-config.h:86:3: warning: #warning "you should set MAGICKCORE_HDRI_ENABLE to sensible default set it to configure time default" [-Wcpp] 86 | # warning "you should set MAGICKCORE_HDRI_ENABLE to sensible default set it to configure time default" | ^~~ D:\msys64\mingw64\include\ImageMagick-7/MagickCore/magick-config.h:87:3: warning: #warning "this is an obsolete behavior please fix yours makefile" [-Wcpp] 87 | # warning "this is an obsolete behavior please fix yours makefile" | ^~~

become the error: C:\sp_64\sp-5.38.0-PDL\c\include\ImageMagick-7/MagickCore/magick-config.h:86:3: error: #error "you should set MAGICKCORE_HDRI_ENABLE" 86 | # error "you should set MAGICKCORE_HDRI_ENABLE" | ^~~~~

If not for that, I think this attempted build against the github version of ImageMagick would have been fine. (Of course, I can't be certain of that until I work out how to work around that error.)

Cheers, Rob

sisyphus commented 9 months ago

Of course, I can't be certain of that until I work out how to work around that error.

Turned out to be fairly simple. Here's the procedure I followed from start to finish.

In MSYS2's (or Cygwin's) bash shell, clone the current github ImageMagick into D:\s\ImageMagick:

$ git clone https://github.com/ImageMagick/ImageMagick /cygdrive/d/s/ImageMagick3

In MSYS2 shell, build this source using the same compiler that StrawberryPerl uses. This compiler is available from: https://github.com/brechtsanders/winlibs_mingw/releases/download/13.1.0-16.0.5-11.0.0-msvcrt-r5/winlibs-x86_64-posix-seh-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5.zip Use that compiler in preference to the one that ships with StrawberryPerl, as the one that ships with StrawberryPerl has (for our intents and purposes) been polluted by the inclusion of some 3rd party libraries. It seems that we need to use the msys2 version of those "pollutent" libraries, rather than StrawberryPerl's version. (At least, using StrawberryPerl's compiler, the ImageMagick github source won't build successfully.) For me, this gcc-13.1.0 has been installed in C:\winpos-gcc-1310\mingw64\bin. My (portable) StrawberryPerl is in C:/sp/_64/sp-5.38.0-PDL I need to install the ImageMagick library into StrawberryPerl's c/bin, c/lib and c/include folders. Owner@DESKTOP-88J497T MINGW64 ~ $ gcc --version -bash: gcc: command not found Owner@DESKTOP-88J497T MINGW64 ~ $ export PATH=$PATH:/c/winpos-gcc-1310/mingw64/bin Owner@DESKTOP-88J497T MINGW64 ~ $ gcc --version gcc.exe (MinGW-W64 x86_64-msvcrt-posix-seh, built by Brecht Sanders) 13.1.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Owner@DESKTOP-88J497T MINGW64 ~ $ cd /d/s/ImageMagick3 Owner@DESKTOP-88J497T MINGW64 /d/s/ImageMagick3 $ ./configure --prefix=/c/sp/_64/sp-5.38.0-PDL/c CPPFLAGS=-I/c/winpos-gcc-1310/mingw64/include LDFLAGS=-L/c/winpos-gcc-1310/mingw64/lib Then, when 'configure' step has completed, we build using MSYS2's 'make' utility: $ make Then, when 'make' step has completed: $ make check For me, 4 of the 87 test files reported "FAIL". All others passed. Then, when 'make check' has concluded: $ make install

In C:\sp_64\sp-5.38.0-PDL\c\lib, create a copy of the newly installed libMagickCore-7.Q16HDRI.dll.a, named libMagickCore.dll.a (because the Image-Magick-7.1.1 build expects the import library to have the shortened name).

Then, open up a new cmd.exe shell running StrawberryPerl. In that shell 'cd' to the unpacked Image-Magick-7.1.1 source: C:\sp_64\sp-5.38.0-PDL>D: D:>cd \s\Image-Magick-7.1.1 D:\s\Image-Magick-7.1.1> set CPATH=%CPATH%;C:\sp_64\sp-5.38.0-PDL\c\include\ImageMagick-7 D:\s\Image-Magick-7.1.1> set LIBRARY_PATH=%LIBRARY_PATH%;C:\sp_64\sp-5.38.0-PDL\c\lib\ImageMagick-7

Because I've built in the MSYS shell, there are some dlls in D:\msys64\mingw64\bin that need to be found for the Image-Magick-7.1.1 (perl module) build to succeed. They also need to be found when the Image-Magick-7.1.1 (perl module) is loaded. So I also append D:\msys64\mingw64\bin to the PATH: D:\s\Image-Magick-7.1.1> set PATH=%PATH%;D:\msys64\mingw64\bin

To make sure this perl build I'm about to do doesn't reference any ImageMagick dlls in D:\msys64\mingw64\bin (placed there earlier by pacman), I rename the extension of those 3 dlls from ".dll" to ".dll_hide".

The following patch to C://sp/_64/sp-5.38.0-PDL/c/include/ImageMagick-7/MagickCore/magick-config.h provides a fairly simple hack that enables the perl module to build. All it does is comment out 3 short sections of pre-processing code:

$ diff -wu magick-config.h_orig magick-config.h
--- magick-config.h_orig        2023-10-08 16:28:51.606113500 +1100
+++ magick-config.h     2023-10-08 15:39:20.749668400 +1100
@@ -66,9 +66,11 @@
 #endif

 /* Number of bits in a pixel Quantum (8/16/32/64) */
+/*
 #ifndef MAGICKCORE_QUANTUM_DEPTH
 # error "you should set MAGICKCORE_QUANTUM_DEPTH"
 #endif
+*/

 /* check values */
 #if MAGICKCORE_QUANTUM_DEPTH != 8
@@ -82,9 +84,11 @@
 #endif

 /* whether HDRI is enable */
+/*
 #if !defined(MAGICKCORE_HDRI_ENABLE)
 # error "you should set MAGICKCORE_HDRI_ENABLE"
 #endif
+*/

 #if MAGICKCORE_HDRI_ENABLE
 # define MAGICKCORE_HDRI_SUPPORT 1
@@ -117,9 +121,11 @@
 #endif

 /* whether HDRI is enable */
+/*
 #if !defined(MAGICKCORE_HDRI_ENABLE)
 # error "you should set MAGICKCORE_HDRI_ENABLE"
 #endif
+*/

 #if MAGICKCORE_HDRI_ENABLE
 # define MAGICKCORE_HDRI_SUPPORT 1

Then run perl Makefile.PL, gmake test, gmake install.

Cheers, Rob

hakonhagland commented 9 months ago

Here's the procedure I followed from start to finish.

@sisyphus Thanks for the detailed procuedure. I will try to reproduce these steps later today.

hakonhagland commented 9 months ago

Here's the procedure I followed from start to finish.

@sisyphus Started on the procedure:

Downloaded and extracted winlibs MSVCRT GCC 13.1.0 64bit: https://github.com/brechtsanders/winlibs_mingw/releases/download/13.1.0-11.0.0-msvcrt-r5/winlibs-x86_64-mcf-seh-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5.zip

$ make
[...]

 CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-uil.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-url.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-uyvy.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-vicar.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-vid.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-video.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-viff.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-vips.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-wbmp.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-wpg.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-xbm.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-xc.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-xcf.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-xpm.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-xps.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-yaml.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-ycbcr.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-yuv.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-clipboard.lo
  CC       coders/MagickCore_libMagickCore_7_Q16HDRI_la-emf.lo
  CC       filters/MagickCore_libMagickCore_7_Q16HDRI_la-analyze.lo
  CCLD     MagickCore/libMagickCore-7.Q16HDRI.la

*** Warning: linker path does not have real file for library -lgdi32.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libgdi32 but no candidates were found. (...for file magic test)

*** Warning: linker path does not have real file for library -luser32.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libuser32 but no candidates were found. (...for file magic test)

*** Warning: linker path does not have real file for library -lws2_32.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libws2_32 and none of the candidates passed a file format test
*** using a file magic. Last file checked: /usr/lib/libpthread.a

*** Warning: linker path does not have real file for library -lurlmon.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with liburlmon and none of the candidates passed a file format test
*** using a file magic. Last file checked: /usr/lib/libpthread.a
*** The inter-library dependencies that have been dropped here will be
*** automatically added whenever a program is linked with this library
*** or is declared to -dlopen it.

*** Since this library must not contain undefined symbols,
*** because either the platform does not support them or
*** it was explicitly requested with -no-undefined,
*** libtool will only create a static version of it.
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-animate.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-compare.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-composite.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-conjure.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-convert.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-deprecate.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-display.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-drawing-wand.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-identify.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-import.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-magick-cli.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-magick-image.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-magick-property.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-magick-wand.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-mogrify.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-montage.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-operation.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-pixel-iterator.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-pixel-wand.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-script-token.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-stream.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-wand.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-wandcli.lo
  CC       MagickWand/libMagickWand_7_Q16HDRI_la-wand-view.lo
  CCLD     MagickWand/libMagickWand-7.Q16HDRI.la

*** Warning: This system cannot link to static lib archive MagickCore/libMagickCore-7.Q16HDRI.la.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have.

*** Warning: linker path does not have real file for library -lgdi32.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libgdi32 but no candidates were found. (...for file magic test)

*** Warning: linker path does not have real file for library -luser32.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libuser32 but no candidates were found. (...for file magic test)

*** Warning: linker path does not have real file for library -lws2_32.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with libws2_32 and none of the candidates passed a file format test
*** using a file magic. Last file checked: /usr/lib/libpthread.a

*** Warning: linker path does not have real file for library -lurlmon.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have
*** because I did check the linker path looking for a file starting
*** with liburlmon and none of the candidates passed a file format test
*** using a file magic. Last file checked: /usr/lib/libpthread.a
*** The inter-library dependencies that have been dropped here will be
*** automatically added whenever a program is linked with this library
*** or is declared to -dlopen it.

*** Since this library must not contain undefined symbols,
*** because either the platform does not support them or
*** it was explicitly requested with -no-undefined,
*** libtool will only create a static version of it.
  CXXLD    utilities/magick.exe
g++: error: unrecognized command-line option '-municode'
make[1]: *** [Makefile:8197: utilities/magick.exe] Error 1
make[1]: Leaving directory '/home/hakon/test/ImageMagick2'
make: *** [Makefile:6243: all] Error 2
sisyphus commented 9 months ago

@hakonhagland, is that 'make' step using the compiler in C:\Winlibs ? In the msys shell, check that thegcc --version report includes the string gcc (MinGW-W64 x86_64-msvcrt-mcf-seh, built by Brecht Sanders) 13.1.0. If it does, then the problem might be that it uses the "mcf" threading model, whereas the one that Strawberry uses has "posix" threads. I don't think that difference should matter .... but maybe you do need the posix threads version: gcc (MinGW-W64 x86_64-msvcrt-posix-seh, built by Brecht Sanders) 13.1.0

More likely, there's a dependency or 2 missing. What did the summary at the end of the configure step report ? UPDATE: I get: CPPFLAGS = -I/c/winpos-gcc-1310/mingw64/include -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_CHANNEL_MASK_DEPTH=32 -DMAGICKCORE_QUANTUM_DEPTH=16 -D_DLL -D_MT PCFLAGS = DEFS = -DHAVE_CONFIG_H LDFLAGS = -L/c/winpos-gcc-1310/mingw64/lib LIBS = -llcms2 -llcms2_fast_float -ltiff -lfreetype -lraqm -llqr-1 -lglib-2.0.dll -lintl.dll -lpng16 -L/mingw64/lib -ldjvulibre -lfontconfig -lfreetype -lheif -lwebpmux -lwebpdemux -lwebp -llzma -lopenjp2 -lpangocairo-1.0 -lpango-1.0 -lgobject-2.0.dll -lglib-2.0.dll -lintl.dll -lharfbuzz -lcairo -lraw_r -lstdc++ -fopenmp -llcms2 -llcms2_fast_float -lxml2 -lz -lgdi32 -luser32 -lm -lpthread CXX = g++ CXXFLAGS = -g -O2 -pthread FEATURES = DPC HDRI Cipher OpenMP DELEGATES = djvu fontconfig freetype heic jp2 lcms lqr lzma pangocairo png ps raqm raw tiff webp xml zlib zstd I'd install the MSYS2 version of ImageMagick first, and hope that installs the dependencies you need: $ pacman -S mingw64/mingw-w64-x86_64-imagemagick and then start over afresh.

Cheers, Rob

hakonhagland commented 9 months ago

The following patch to C://sp/_64/sp-5.38.0-PDL/c/include/ImageMagick-7/MagickCore/magick-config.h provides a fairly simple hack that enables the perl module to build.

@sisyphus It would be interesting to know more details on why this hack is needed..

hakonhagland commented 9 months ago

is that 'make' step using the compiler in C:\Winlibs ?

@sisyphus No it is not, I forgot to update PATH such it could find it. Here is my next attempt:

[...] Options used to compile and link: PREFIX = /c/Strawberry/c EXEC-PREFIX = /c/Strawberry/c VERSION = 7.1.1-21 CC = gcc CFLAGS = -fopenmp -Wall -g -O2 -mtune=core2 -fexceptions -pthread -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_CHANNEL_MASK_DEPTH=32 -DMAGICKCORE_QUANTUM_DEPTH=16 CPPFLAGS = -I/c/Winlibs/mingw64/include -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_CHANNEL_MASK_DEPTH=32 -DMAGICKCORE_QUANTUM_DEPTH=16 -D_DLL -D_MT PCFLAGS = DEFS = -DHAVE_CONFIG_H LDFLAGS = -L/c/Winlibs/mingw64/lib LIBS = -lgdi32 -luser32 -lm -lpthread CXX = g++ CXXFLAGS = -g -O2 -pthread FEATURES = DPC HDRI Cipher OpenMP DELEGATES = ps

- Ran `make`
- Ran `make install`
- Change to directory: `cd /c/perl`, downloaded PerlMagick:

$ wget https://imagemagick.org/archive/perl/Image-Magick-7.1.1-18.tar.gz $ tar zxvf Image-Magick-7.1.1-18.tar.gz

- Changed to powershell terminal window

cd C:\perl\Image-Magick-7.1.1\ (Get-Command perl).Path C:\Strawberry\perl\bin\perl.exe perl --version This is perl 5, version 38, subversion 0 (v5.38.0) built for MSWin32-x64-multi-thread

- Ran `perl Makefile.PL`

perl Makefile.PL Gonna create 'libMagickCore.a' from 'C:\Strawberry\c\bin\libMagickCore-7.Q16HDRI-10.dll' ################################### WARNING! ###################################

It seems that you are trying to install Perl::Magick on a MS Windows box with

perl + gcc compiler (e.g. strawberry perl), however we cannot find ImageMagick

binaries installed on your system.

#

Please check the following prerequisites:

#

1) You need to have installed ImageMagick Windows binaries from

https://imagemagick.org/script/binary-releases.php#windows

#

2) We only support dynamic (DLL) ImageMagick binaries

note: it is not possible to mix 32/64-bit binaries of perl and ImageMagick

#

3) During installation select that you want to install ImageMagick's

development files (libraries+headers)

#

4) You NEED TO have ImageMagick's directory in your PATH. We are

using the 'magick' tool to determine your actual configuration.

#

5) You might need Visual C++ Redistributable Package installed on your system

see instructions on ImageMagick's Binary Release webpage

#

We are gonna continue, but chances for successful build are very low!

################################################################################ Generating a gmake-style Makefile Writing Makefile for Image::Magick Writing MYMETA.yml and MYMETA.json

- Ran `gmake`

gmake Skip blib\lib\Image\Magick.pm (unchanged) Running Mkbootstrap for Magick () "C:\Strawberry\perl\bin\perl.exe" -MExtUtils::Command -e chmod -- 644 "Magick.bs" "C:\Strawberry\perl\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempty -- Magick.bs blib\arch\auto\Image\Magick\Magick.bs 644 gcc -c -DWIN32 -DWIN64 -DPERL_TEXTMODE_SCRIPTS -DMULTIPLICITY -DPERL_IMPLICIT_SYS -DUSE_PERLIO -D__USE_MINGW_ANSI_STDIO -fwrapv -fno-strict-aliasing -mms-bitfields -Os -DVERSION=\"7.1.1\" -DXS_VERSION=\"7.1.1\" "-IC:\STRAWB~1\perl\lib\CORE" -D_LARGE_FILES=1 -DHAVE_CONFIG_H Magick.c Magick.xs:56:10: fatal error: MagickCore/MagickCore.h: No such file or directory 56 | #include <MagickCore/MagickCore.h> | ^~~~~~~~~ compilation terminated. gmake: *** [makefile:350: Magick.o] Error 1

- Set CPATH environment variable to find header files:

$env:CPATH = 'C:\Strawberry\c\include\ImageMagick-7' perl Makefile.PL gmake Skip blib\lib\Image\Magick.pm (unchanged) Running Mkbootstrap for Magick () "C:\Strawberry\perl\bin\perl.exe" -MExtUtils::Command -e chmod -- 644 "Magick.bs" "C:\Strawberry\perl\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempty -- Magick.bs blib\arch\auto\Image\Magick\Magick.bs 644 gcc -c -DWIN32 -DWIN64 -DPERL_TEXTMODE_SCRIPTS -DMULTIPLICITY -DPERL_IMPLICIT_SYS -DUSE_PERLIO -D__USE_MINGW_ANSI_STDIO -fwrapv -fno-strict-aliasing -mms-bitfields -Os -DVERSION=\"7.1.1\" -DXS_VERSION=\"7.1.1\" "-IC:\STRAWB~1\perl\lib\CORE" -D_LARGE_FILES=1 -DHAVE_CONFIG_H Magick.c In file included from C:\Strawberry\c\include\ImageMagick-7/MagickCore/MagickCore.h:29, from Magick.xs:56: C:\Strawberry\c\include\ImageMagick-7/MagickCore/magick-config.h:63:3: warning: #warning "you should set MAGICKCORE_QUANTUM_DEPTH to sensible default set it to configure time default" [-Wcpp] 63 | # warning "you should set MAGICKCORE_QUANTUM_DEPTH to sensible default set it to configure time default" | ^~~ C:\Strawberry\c\include\ImageMagick-7/MagickCore/magick-config.h:64:3: warning: #warning "this is an obsolete behavior please fix your makefile" [-Wcpp] 64 | # warning "this is an obsolete behavior please fix your makefile" | ^~~ C:\Strawberry\c\include\ImageMagick-7/MagickCore/magick-config.h:86:3: error: #error "you should set MAGICKCORE_HDRI_ENABLE" 86 | # error "you should set MAGICKCORE_HDRI_ENABLE" | ^~~~~ C:\Strawberry\c\include\ImageMagick-7/MagickCore/magick-config.h:121:3: error: #error "you should set MAGICKCORE_HDRI_ENABLE" 121 | # error "you should set MAGICKCORE_HDRI_ENABLE" | ^~~~~

- Modified `/c/Strawberry/c/include/ImageMagick-7/MagickCore/magick-config.h` as suggested in https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/139#issuecomment-1751934125
- Reran `gmake`

gmake Skip blib\lib\Image\Magick.pm (unchanged) Running Mkbootstrap for Magick () "C:\Strawberry\perl\bin\perl.exe" -MExtUtils::Command -e chmod -- 644 "Magick.bs" "C:\Strawberry\perl\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempty -- Magick.bs blib\arch\auto\Image\Magick\Magick.bs 644 gcc -c -DWIN32 -DWIN64 -DPERL_TEXTMODE_SCRIPTS -DMULTIPLICITY -DPERL_IMPLICIT_SYS -DUSE_PERLIO -D__USE_MINGW_ANSI_STDIO -fwrapv -fno-strict-aliasing -mms-bitfields -Os -DVERSION=\"7.1.1\" -DXS_VERSION=\"7.1.1\" "-IC:\STRAWB~1\perl\lib\CORE" -D_LARGE_FILES=1 -DHAVE_CONFIG_H Magick.c In file included from C:\Strawberry\c\include\ImageMagick-7/MagickCore/MagickCore.h:29, from Magick.xs:56: C:\Strawberry\c\include\ImageMagick-7/MagickCore/magick-config.h:81:6: error: #error "MAGICKCORE_QUANTUM_DEPTH is not 8/16/32/64 bits" 81 | # error "MAGICKCORE_QUANTUM_DEPTH is not 8/16/32/64 bits" | ^~~~~

sisyphus commented 9 months ago

@sisyphus It would be interesting to know more details on why this hack is needed..

Yes. On the face of it, it seems that they've recently decided`to make it a fatal error, rather than just a warning. While all of the Image-Magick-7.1.1 (perl module) checks are passing, I'm not too concerned about it. I think that if the hack is not breaking the build or allowing any tests to fail, then it's ok to "worry about it later" ... but it should be dealt with.

Perhaps you need to comment out one more little bit of preprocessing in magick-config.h. I think I did see that code in magick-config.h, but it wasn't posing a problem for my build, so I left it in place. OTOH, if "MAGICKCORE_QUANTUM_DEPTH is not 8/16/32/64 bits", things are not looking all that promising.

The configure summary you got looks deficient in comparison to what I got. (See the "update" in my previous post.) There's a lot of LIBS that don't get mentioned for you. And your DELEGATES entry is quite bare. As I said, you might find that using pacman to install ImageMagick into your MSYS2/mingw64 will install some libraries that will add to the usefulness of your own ImageMagick build.

It might even be a good thing for you to first build Image-Magick-7.1.1 against that MSYS2/mingw64 ImageMagick library. You can always come back later to building your own lmageMagick library from github source, and then rebuild Image-Magick-7.1.1 against it. With the MSYS2/mingw64 installation of ImageMagick, I found no need for any hacking of magick-config.h.

Cheers, Rob

hakonhagland commented 9 months ago

error "MAGICKCORE_QUANTUM_DEPTH is not 8/16/32/64 bits"

I suspect the problem comes from this line:

$INC_magick       = "$Ipaths";

Compare with the similar line for Linux:

my $INC_magick = '-I../ -I@top_srcdir@ @CPPFLAGS@ -I"' . $Config{'usrinc'} . '/ImageMagick"';

here I suspect the template substitution variable @CPPFLAGS@ will contain a -DMAGICKCORE_QUANTUM_DEPTH=16 flag.. This could explain why the variable is defined on Linux but not on Windows?

hakonhagland commented 9 months ago

error "MAGICKCORE_QUANTUM_DEPTH is not 8/16/32/64 bits"

Added possible fix here: https://github.com/ImageMagick/ImageMagick/pull/6770

hakonhagland commented 9 months ago

I suspect the template substitution variable @CPPFLAGS@ will contain a -DMAGICKCORE_QUANTUM_DEPTH=16 flag

@sisyphus Yes it works if apply the following patch to Makefile.PL

178c178
<   $CCFLAGS_magick   = "$Config{'ccflags'} -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16";
---
>   $CCFLAGS_magick   = "$Config{'ccflags'}";

then rerun Makefile.PL:

> perl Makefile.PL
Gonna create 'libMagickCore.a' from 'C:\Strawberry\c\bin\libMagickCore-7.Q16HDRI-10.dll'
################################### WARNING! ###################################
# It seems that you are trying to install Perl::Magick on a MS Windows box with
# perl + gcc compiler (e.g. strawberry perl), however we cannot find ImageMagick
# binaries installed on your system.
#
# Please check the following prerequisites:
#
# 1) You need to have installed ImageMagick Windows binaries from
#    https://imagemagick.org/script/binary-releases.php#windows
#
# 2) We only support dynamic (DLL) ImageMagick binaries
#    note: it is not possible to mix 32/64-bit binaries of perl and ImageMagick
#
# 3) During installation select that you want to install ImageMagick's
#    development files (libraries+headers)
#
# 4) You NEED TO have ImageMagick's directory in your PATH.  We are
#    using the 'magick' tool to determine your actual configuration.
#
# 5) You might need Visual C++ Redistributable Package installed on your system
#    see instructions on ImageMagick's Binary Release webpage
#
# We are gonna continue, but chances for successful build are very low!
################################################################################
Generating a gmake-style Makefile
Writing Makefile for Image::Magick
Writing MYMETA.yml and MYMETA.json
hakonhagland commented 9 months ago

The configure summary you got looks deficient in comparison to what I got. (See the "update" in my previous post.) There's a lot of LIBS that don't get mentioned for you.

@sisyphus Apparently those libraries are not needed to build Image::Magick then (since I was able to install the module without them now) ?

hakonhagland commented 9 months ago

Refer to: https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/139#issuecomment-1751934125 :

Use that compiler in preference to the one that ships with StrawberryPerl, as the one that ships with StrawberryPerl has (for our intents and purposes) been polluted by the inclusion of some 3rd party libraries. It seems that we need to use the msys2 version of those "pollutent" libraries, rather than StrawberryPerl's version.

@sisyphus Maybe we should investigate this more? It would be better if we could use the one that ships with StrawberryPerl, right?

shawnlaffan commented 9 months ago

It would be good to know which libraries aren't working.

It could be clashes where SP provides DLLs that are also provided by Winlibs, e.g. there is libbz.dll (Winlibs) and libbz2-1__.dll (SP).

Previous discussion starts here: https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/57#issuecomment-1519198105

sisyphus commented 9 months ago

It would be good to know which libraries aren't working.

It's only when building the ImageMagick library from source that I struck any issues with using the StrawberryPerl-5.38.0-PDL compiler in the Strawberry Perl environment. (I'll repeat that exercise and post the results later.) If I used the same compiler, removed from the StrawberryPerl environment then there was no issue.

Building Image-Magick-7.1.1 (perl module) is quite simple if you're building against the ImageMagick installed into MSYS2/mingw64 by pacman. (See below.) You'll see (below) some compilation warnings emitted during the gmake stage. In the current github source, some of those warnings have been turned into errors. The simplest workaround, if you want to build Image-Magick-7.1.1 against github ImageMagick is to revert those changes by patching magick-config.h as I showed earlier.

Welcome to Strawberry Perl PDL Edition!

  • URL - https://strawberryperl.com + http://pdl.perl.org
  • to launch perl script run: perl c:\my\scripts\pdl-test.pl
  • to start PDL console run: pdl2
  • to update PDL run: cpanm PDL
  • to install extra module run: cpanm PDL::Any::Module or if previous fails: ppm PDL::Any::Module
  • or you can use dev tools like: gcc, g++, gfortran, gmake
  • see README.TXT for more info

    Perl executable: C:\sp_64\sp-5.38.0-PDL\perl\bin\perl.exe Perl version : 5.38.0 / MSWin32-x64-multi-thread PDL version : 2.084

C:\sp_64\sp-5.38.0-PDL>D:

D:>cd \s\Image-Magick-7.1.1-3

D:\s\Image-Magick-7.1.1-3>set PATH=%PATH%;D:\msys64\mingw64\bin

D:\s\Image-Magick-7.1.1-3>set CPATH=%CPATH%;D:\msys64\mingw64\include;D:\msys64\mingw64\include\ImageMagick-7

D:\s\Image-Magick-7.1.1-3>set LIBRARY_PATH=D:\msys64\mingw64\lib

D:\s\Image-Magick-7.1.1-3>copy D:\msys64\mingw64\lib\libMagickCore-7.Q16HDRI.dll.a D:\msys64\mingw64\lib\libMagickCore.dll.a Overwrite D:\msys64\mingw64\lib\libMagickCore.dll.a? (Yes/No/All): Yes 1 file(s) copied.

D:\s\Image-Magick-7.1.1-3>perl Makefile.PL Gonna create 'libMagickCore.a' from 'C:\sp_64\sp-5.38.0-PDL\c\bin\libMagickCore-7.Q16HDRI-10.dll' ################################### WARNING! ################################### # It seems that you are trying to install Perl::Magick on a MS Windows box with # perl + gcc compiler (e.g. strawberry perl), however we cannot find ImageMagick # binaries installed on your system. # # Please check the following prerequisites: # # 1) You need to have installed ImageMagick Windows binaries from # https://imagemagick.org/script/binary-releases.php#windows # # 2) We only support dynamic (DLL) ImageMagick binaries # note: it is not possible to mix 32/64-bit binaries of perl and ImageMagick # # 3) During installation select that you want to install ImageMagick's # development files (libraries+headers) # # 4) You NEED TO have ImageMagick's directory in your PATH. We are # using the 'magick' tool to determine your actual configuration. # # 5) You might need Visual C++ Redistributable Package installed on your system # see instructions on ImageMagick's Binary Release webpage # # We are gonna continue, but chances for successful build are very low! ################################################################################ Checking if your kit is complete... Looks good Generating a gmake-style Makefile Writing Makefile for Image::Magick Writing MYMETA.yml and MYMETA.json

D:\s\Image-Magick-7.1.1-3>gmake test Running Mkbootstrap for Magick () "C:\sp_64\sp-5.38.0-PDL\perl\bin\perl.exe" -MExtUtils::Command -e chmod -- 644 "Magick.bs" "C:\sp_64\sp-5.38.0-PDL\perl\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempty -- Magick.bs blib\arch\auto\Image\Magick\Magick.bs 644 "C:\sp_64\sp-5.38.0-PDL\perl\bin\perl.exe" "C:\sp_64\sp-5.38.0-PDL\perl\lib\ExtUtils/xsubpp" -typemap C:\sp_64\sp-5.38.0-PDL\perl\lib\ExtUtils\typemap -typemap D:\s\Image-Magick-7.1.1-3\typemap Magick.xs > Magick.xsc "C:\sp_64\sp-5.38.0-PDL\perl\bin\perl.exe" -MExtUtils::Command -e mv -- Magick.xsc Magick.c gcc -c -DWIN32 -DWIN64 -DUSE_MINGW_ANSI_STDIO -DPERL_TEXTMODE_SCRIPTS -DMULTIPLICITY -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DUSE_MINGW_ANSI_STDIO -fwrapv -fno-strict-aliasing -mms-bitfields -Os -DVERSION=\"7.1.1\" -DXS_VERSION=\"7.1.1\" "-IC:\sp_64\sp-5.38.0-PDL\perl\lib\CORE" -D_LARGE_FILES=1 -DHAVE_CONFIG_H Magick.c In file included from D:\msys64\mingw64\include\ImageMagick-7/MagickCore/MagickCore.h:29, from Magick.xs:56: D:\msys64\mingw64\include\ImageMagick-7/MagickCore/magick-config.h:63:3: warning: #warning "you should set MAGICKCORE_QUANTUM_DEPTH to sensible default set it to configure time default" [-Wcpp] 63 # warning "you should set MAGICKCORE_QUANTUM_DEPTH to sensible default set it to configure time default" ^~~ D:\msys64\mingw64\include\ImageMagick-7/MagickCore/magick-config.h:64:3: warning: #warning "this is an obsolete behavior please fix your makefile" [-Wcpp] 64 # warning "this is an obsolete behavior please fix your makefile" ^~~ D:\msys64\mingw64\include\ImageMagick-7/MagickCore/magick-config.h:86:3: warning: #warning "you should set MAGICKCORE_HDRI_ENABLE to sensible default set it to configure time default" [-Wcpp] 86 # warning "you should set MAGICKCORE_HDRI_ENABLE to sensible default set it to configure time default" ^~~ D:\msys64\mingw64\include\ImageMagick-7/MagickCore/magick-config.h:87:3: warning: #warning "this is an obsolete behavior please fix yours makefile" [-Wcpp] 87 # warning "this is an obsolete behavior please fix yours makefile" ^~~ In file included from Magick.xs:59: C:\sp_64\sp-5.38.0-PDL\perl\lib\CORE/XSUB.h:569: warning: "fstat" redefined 569 # define fstat PerlLIO_fstat
In file included from C:\sp_64\sp-5.38.0-PDL\perl\lib\CORE/perl.h:1789, from Magick.xs:58: C:/sp/_64/sp-5.38.0-PDL/c/x86_64-w64-mingw32/include/sys/stat.h:280: note: this is the location of the previous definition 280 #define fstat _fstat64
C:\sp_64\sp-5.38.0-PDL\perl\lib\CORE/XSUB.h:573: warning: "lseek" redefined 573 # define lseek PerlLIO_lseek
In file included from C:/sp/_64/sp-5.38.0-PDL/c/x86_64-w64-mingw32/include/sys/stat.h:14: C:/sp/_64/sp-5.38.0-PDL/c/x86_64-w64-mingw32/include/io.h:352: note: this is the location of the previous definition 352 #define lseek lseek64
C:\sp_64\sp-5.38.0-PDL\perl\lib\CORE/XSUB.h:580: warning: "stat" redefined 580 # define stat(buf,sb) PerlLIO_stat(buf,sb)
C:/sp/_64/sp-5.38.0-PDL/c/x86_64-w64-mingw32/include/sys/stat.h:279: note: this is the location of the previous definition 279 #define stat _stat64

"C:\sp_64\sp-5.38.0-PDL\perl\bin\perl.exe" -MExtUtils::Mksymlists \ -e "Mksymlists('NAME'=>\"Image::Magick\", 'DLBASE' => 'Magick', 'DL_FUNCS' => { }, 'FUNCLIST' => [], 'IMPORTS' => { }, 'DL_VARS' => []);" g++.exe Magick.def -o blib\arch\auto\Image\Magick\Magick.xs.dll -mdll -s -L"C:\sp_64\sp-5.38.0-PDL\perl\lib\CORE" -L"C:\sp_64\sp-5.38.0-PDL\c\lib" -L"D:/s/Image-Magick-7.1.1-3" -L"C:\sp_64\sp-5.38.0-PDL\c\lib" Magick.o "C:\sp_64\sp-5.38.0-PDL\perl\lib\CORE\libperl538.a" "libMagickCore.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libmoldname.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libkernel32.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libuser32.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libgdi32.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libwinspool.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libcomdlg32.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libadvapi32.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libshell32.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libole32.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\liboleaut32.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libnetapi32.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libuuid.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libws2_32.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libmpr.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libwinmm.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libversion.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libodbc32.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libodbccp32.a" "C:\sp_64\sp-5.38.0-PDL\c\x86_64-w64-mingw32\lib\libcomctl32.a" -Wl,--enable-auto-image-base "C:\sp_64\sp-5.38.0-PDL\perl\bin\perl.exe" -MExtUtils::Command -e chmod -- 755 blib\arch\auto\Image\Magick\Magick.xs.dll cp Magick.pm blib\lib\Image\Magick.pm AutoSplitting blib\lib\Image\Magick.pm (blib\lib\auto\Image\Magick) "C:\sp_64\sp-5.38.0-PDL\perl\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef Test::Harness::Switches; test_harness(0, 'blib\lib', 'blib\arch')" t/.t t/blob.t .......... ok t/composite.t ..... ok t/filter.t ........ ok t/getattribute.t .. ok t/montage.t ....... ok t/ping.t .......... ok t/read.t .......... ok t/setattribute.t .. ok t/write.t ......... ok All tests successful. Files=9, Tests=273, 2 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU) Result: PASS

D:\s\Image-Magick-7.1.1-3>gmake install "C:\sp_64\sp-5.38.0-PDL\perl\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempty -- Magick.bs blib\arch\auto\Image\Magick\Magick.bs 644 Files found in blib\arch: installing files in blib\lib into architecture dependent library tree Installing C:\sp_64\sp-5.38.0-PDL\perl\site\lib\auto\Image\Magick\Magick.xs.dll Appending installation info to C:\sp_64\sp-5.38.0-PDL\perl\lib/perllocal.pod Cheers, Rob

sisyphus commented 9 months ago

It would be good to know which libraries aren't working.

@shawnlaffan, I re-tried building with StrawberryPerl's compiler and struck no significant issues this time. (Dunno what happened last time, when it all went to shit.)

So ... for the msys2 build of ImageMagick, I appended my Strawberry c/bin to the PATH, set CPPFLAGS to the location of Strawberry c/include, set LDFLAGS to the location of Strawberry c/lib and set --prefix to the location of Strawberry c folder.

However, I think the build used the stuff in the MSYS2 installation - and probably no stuff (except for the compiler) from Strawberry Perl. 'make check' failed the 4 usual files, and 'make install' put the completed build into the appropriate places within my Strawberry location.

When building Image-Magick-7.1.1 (which is done in the cmd.exe shell that my portableshell.bat opens up), I had to append D:\msys64\mingw32\bin to the PATH to get 'gmake test' to succeed. And I still need to have D:\msys64\mingw\bin in the PATH to use the module. (It is, however, using the ImageMagick dlls that were installed (by MSYS2's 'make install') into Strawberry's c/bin folder.

There's at least 50 dlls from my MSYS2 installation that are needed at Inage-Magick-7.1.1 runtime. (I got sick of trying to track them all down.)

Cheers, Rob

hakonhagland commented 9 months ago

This thread has now become so long that I think it will be difficult to follow it in the future. Would it be an idea to create separate documentation for how to install Perl XS modules under Strawberry Perl? For example a main document "Installing-XS-modules.md" with links to sub documents for specific modules, like "Image-Magick.md" ? Then we could condense (make more readable) the findings that we have done in this thread (#139) into that documentation file (the steps needed to install the module) for the future. What do you think @shawnlaffan and @sisyphus ?

sisyphus commented 9 months ago

This thread has now become so long that I think it will be difficult to follow it in the future.

I've been struggling to follow it for the last few days ;-) (I didn't want to complain because it's mainly my fault.)

Cheers, Rob

genio commented 9 months ago

@hakonhagland Start using the Wiki to make said .md and once ironed out sufficiently there, we can either put it in the main repo or just link to it.

hakonhagland commented 9 months ago

Start using the Wiki to make said .md

@genio Good idea, I created a new issue for this here: https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/141 where we can continue the discussion.

hakonhagland commented 9 months ago

Refer to https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/139#issuecomment-1754707364

And I still need to have D:\msys64\mingw\bin in the PATH to use the module.

@sisyphus We should investigate this further, we do not want any dependencies back to msys2 after the perl module has been installed, right? Then, for example if you later choose to delete MSYS2 from your machine the perl module will stop to work.

shawnlaffan commented 9 months ago

The list of DLL dependencies can be obtained using App::PP::AutoLink. Use that to pack a perl file that uses Image::Magick. The list of detected DLLs is printed to the console and can then be edited to copy the needed files to a new location.

I should really extract the DLL search logic into something cleaner but it will work well enough if it's a one-off process.

I've already used it to package the Gtk2 files as an Alien module (there are also PPMs for 5.38 if anyone is interested - look under the releases). https://github.com/shawnlaffan/perl-alien-gtkstack-windows/

sisyphus commented 9 months ago

@sisyphus](https://github.com/sisyphus) We should investigate this further, we do not want any dependencies back to msys2 after the perl module has been installed, right?

Personally, that doesn't bother me too much. But I think it's fair enough to want to avoid that dependency

Is the solution just proposed by @shawnlaffan acceptable ? Building in the MSYS2 shell apparently creates dependencies on thegtk2/3 dlls - and those dlls need to be found at runtime.

You could look at building against the standalone MSVC ImageMagick library that ImageMagick-7.1.1-19-Q16-HDRI-x64-dll.exe installs. For me, that library needs just just one hack - line 279 of its ImageMagick-7.1.1-Q16-HDRI\include/MagickCore/magick-baseconfig.h needs to be commented out. Append the location of the ImageMagick-7.1.1-Q16-HDRI library to the PATH. Then Image-Magick-7.1.1 (perl module) builds straight out of the box on Strawberry Perl.

Welcome to Strawberry Perl Portable Edition!

  • URL - http://www.strawberryperl.com/
  • see README.TXT for more info

    Perl executable: C:\sp_64\sp-5.38.0\perl\bin\perl.exe Perl version : 5.38.0 / MSWin32-x64-multi-thread

C:\sp_64\sp-5.38.0>D:

D:>set PATH=%PATH%;C:\d\ImageMagick-7.1.1-Q16-HDRI

D:>cd \s\Image-Magick-7.1.1

D:\s\Image-Magick-7.1.1>perl Makefile.PL Gonna create 'libMagickCore.a' from 'C:\d\ImageMagick-7.1.1-Q16-HDRI\CORE_RLMagickCore.dll' Checking if your kit is complete... Looks good Generating a gmake-style Makefile Writing Makefile for Image::Magick Writing MYMETA.yml and MYMETA.json

D:\s\Image-Magick-7.1.1-5>gmake test Running Mkbootstrap for Magick () "C:\sp_64\sp-5.38.0\perl\bin\perl.exe" -MExtUtils::Command -e chmod -- 644 "Magick.bs" "C:\sp_64\sp-5.38.0\perl\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempty -- Magick.bs blib\arch\auto\Image\Magick\Magick.bs 644 "C:\sp_64\sp-5.38.0\perl\bin\perl.exe" "C:\sp_64\sp-5.38.0\perl\lib\ExtUtils/xsubpp" -typemap C:\sp_64\sp-5.38.0\perl\lib\ExtUtils\typemap -typemap D:\s\Image-Magick-7.1.1-5\typemap Magick.xs > Magick.xsc "C:\sp_64\sp-5.38.0\perl\bin\perl.exe" -MExtUtils::Command -e mv -- Magick.xsc Magick.c gcc -c -I"C:\d\ImageMagick-7.1.1-Q16-HDRI\include" -DWIN32 -DWIN64 -DUSE_MINGW_ANSI_STDIO -fdiagnostics-color=never -DPERL_TEXTMODE_SCRIPTS -DMULTIPLICITY -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DUSE_MINGW_ANSI_STDIO -fwrapv -fno-strict-aliasing -mms-bitfields -Os -DVERSION=\"7.1.1\" -DXS_VERSION=\"7.1.1\" "-IC:\sp_64\sp-5.38.0\perl\lib\CORE" -D_LARGE_FILES=1 -DHAVE_CONFIG_H Magick.c "C:\sp_64\sp-5.38.0\perl\bin\perl.exe" -MExtUtils::Mksymlists \ -e "Mksymlists('NAME'=>\"Image::Magick\", 'DLBASE' => 'Magick', 'DL_FUNCS' => { }, 'FUNCLIST' => [], 'IMPORTS' => { }, 'DL_VARS' => []);" g++.exe Magick.def -o blib\arch\auto\Image\Magick\Magick.xs.dll -mdll -s -L"C:\sp_64\sp-5.38.0\perl\lib\CORE" -L"C:\sp_64\sp-5.38.0\c\lib" -L"D:/s/Image-Magick-7.1.1-5" -L"C:\d\ImageMagick-7.1.1-Q16-HDRI\lib" Magick.o "C:\sp_64\sp-5.38.0\perl\lib\CORE\libperl538.a" "libMagickCore.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libmoldname.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libkernel32.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libuser32.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libgdi32.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libwinspool.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libcomdlg32.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libadvapi32.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libshell32.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libole32.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\liboleaut32.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libnetapi32.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libuuid.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libws2_32.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libmpr.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libwinmm.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libversion.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libodbc32.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libodbccp32.a" "C:\sp_64\sp-5.38.0\c\x86_64-w64-mingw32\lib\libcomctl32.a" -Wl,--enable-auto-image-base "C:\sp_64\sp-5.38.0\perl\bin\perl.exe" -MExtUtils::Command -e chmod -- 755 blib\arch\auto\Image\Magick\Magick.xs.dll cp Magick.pm blib\lib\Image\Magick.pm AutoSplitting blib\lib\Image\Magick.pm (blib\lib\auto\Image\Magick) "C:\sp_64\sp-5.38.0\perl\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef Test::Harness::Switches; test_harness(0, 'blib\lib', 'blib\arch')" t/.t t/blob.t .......... ok t/composite.t ..... ok t/filter.t ........ ok t/getattribute.t .. ok t/montage.t ....... ok t/ping.t .......... ok

t/read.t .......... ok t/setattribute.t .. ok t/write.t ......... ok All tests successful. Files=9, Tests=273, 2 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU) Result: PASS

D:\s\Image-Magick-7.1.1>
Initially, I had trouble with t/ping.t hanging ... but that's not happening any more. It seems that, if this ImageMagick-7.1.1-Q16-HDRI installation is in the path, then there's no need to specify CPATH or LIBRARY_PATH.

Of course, you still need ImageMagick-7.1.1-Q16-HDRI in Strawberry Perl's PATH. I reckon (untested) you could install the entire ImageMagick-7.1.1-Q16-HDRI installation into Strawberry's c/bin/ImageMagick-7.1.1-Q16-HDR folder, append that folder to the PATH (in the portableshell.bat) and then Image-Magick-7.1.1 is all ready to build/test/install/run as soon as you open up a new shell.

I now don't know where I got this ImageMagick-7.1.1-19-Q16-HDRI-x64-dll.exe from. It's mentioned somewhere in one of these current ImageMagick discussions.

You need to tell the installer (when prompted) to install the extra (essential) stuff, and remember that magick-baseconfig.h needs that simple fix mentioned earlier in this post.

Cheers, Rob

shawnlaffan commented 9 months ago

The advantage of the Alien approach is that it saves the files under .../site/lib/auto/share. The Alien package then adds itself to the path when it is used on the right OS and build type, and is a no-op otherwise (at least that's how I've implemented Alien::GtkStack::Windows). One could also probably use File::ShareDir directly but the Alien infrastructure makes installation and use easier.

The limitation is that each calling script needs a use Alien::XYZ statement at the top, or the PERL5OPT variable needs to be updated.

hakonhagland commented 9 months ago

but the Alien infrastructure makes installation and use easier.

@shawnlaffan Does this mean that the needed libraries can be packed together with the Alien? So there will be no need to install Image::Magick from source (or download the binary release) before installing the perl module? That would be great!

A quick search on metacpan shows that a alien module already exists: https://metacpan.org/pod/Alien::ImageMagick Wonder why the Perl module Image::Magick is not using it for windows? As I understand, then when Image::Magick is installed on windows it could check if libraries are missing and then install Alien::ImageMagick if needed to get the libraries?

hakonhagland commented 9 months ago

Referring to https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/139#issue-1928656724 and https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/139#issuecomment-1751748174 :

$ make 2>&1 | tee make_log.txt [...] C:\msys2\home\hakon\test\ImageMagick/MagickCore/blob.c:1270: undefined reference to `BZ2_bzerror'

Going back to my initial attempt at building, it would be interesting to know more about this linker error so I created a separate issue for this here: https://github.com/ImageMagick/ImageMagick/issues/6777

shawnlaffan commented 9 months ago

@shawnlaffan Does this mean that the needed libraries can be packed together with the Alien? So there will be no need to install Image::Magick from source (or download the binary release) before installing the perl module? That would be great!

Yes, that is the general principle. For the Gtk2 case all the relevant files from the bin, lib and share dirs have been packed.

A quick search on metacpan shows that a alien module already exists: https://metacpan.org/pod/Alien::ImageMagick Wonder why the Perl module Image::Magick is not using it for windows? As I understand, then when Image::Magick is installed on windows it could check if libraries are missing and then install Alien::ImageMagick if needed to get the libraries?

Alien::ImageMagick uses an older style approach that also does not work on Windows since it uses Unix syntax. It should be possible to update it to use Alien::Build but there would still be the need to get all the dependencies in place. That is perhaps best done using a second Alien, or it could be done as a build step on Windows.

hakonhagland commented 9 months ago

It should be possible to update it to use Alien::Build but there would still be the need to get all the dependencies in place. That is perhaps best done using a second Alien, or it could be done as a build step on Windows.

@shawnlaffan Created a new issue to track this idea, see https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/142