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

How to build a perl module that is built using configure script on Linux? #138

Open
hakonhagland opened this issue Oct 4, 2023 · 10 comments

Comments

@hakonhagland
Copy link

Refer to https://stackoverflow.com/q/77226662/2173773. On Linux I can build Image::Magic using the following commands:

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

What should I do to build this module with Strawberry Perl?

@shawnlaffan
Copy link
Contributor

One approach is to use the same environment we use when building all the external libraries.

Docker config: https://github.com/StrawberryPerl/spbuild/tree/gcc13
Setup: https://github.com/StrawberryPerl/build-extlibs

The build process takes a long time but it is possible to download and re-use the existing build artefacts. https://github.com/StrawberryPerl/build-extlibs/releases/tag/dev_gcc13.1_20230606 (the one to use should be the extlibs_gcc_r5.tar file). Extract to the _out directory.

It should also be possible to use an msys2 shell and set the PATH, PKG_CONFIG_PATH etc variables to point to the strawberry perl tree so it uses the compiler and other libs that come with strawberry perl. This is essentially the approach used by Alien::Build. Alien::ImageMagick seems not to use it, though, which might explain its test failures (I have not looked closely).

Alternately Alien::ImageMagick could be updated to use Alien::Build, or an A::B variant could be developed.

@shawnlaffan
Copy link
Contributor

Although both the MSYS2 and Alien::Build approaches will need to account for the additional dependencies. The MSYS2 build system lists cairo as a build time dependencies and glib2 as a runtime. Things might get complex quickly.

Another approach is to adapt the one described by @sisyphus in https://www.perlmonks.org/?node_id=11153998

@sisyphus
Copy link

sisyphus commented Oct 5, 2023

IIUC, it should be pretty much the same with Strawberry Perl, but you'll be running the commands in the MSYS2 shell.

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

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,
(I have deliberately avoided installing gcc into my MSYS2 installation - just so I can easily choose which C toolchain I want by simply appending its location to the PATH.)

And I would think that the --prefix needs to point to Strawberry's "c" folder.
Finally, make install should not need the sudo.

Then just follow the the instructions for building Perl-Magick against that library, using Strawberry Perl.

If you can tell me how I can obtain the exact same ImageMagick source as you're using, I'll give it a go.
I've built both ImageMagick and Perl-Magick this way in the past .... but I've not recently tried it out.

If you're unfamiliar with the MSYS2 shell, note that it sometimes doesn't understand Windows paths like (eg) D:/Strawberry/c/bin, but should always understand /D/Strawberry/c/bin.

Cheers,
Rob

@shawnlaffan
Copy link
Contributor

Thanks @sisyphus Some good points there.

If the --with-perl argument is only needed for the build then the msys2 provided perl will work. If it is also needed at run time then the Strawberry Perl version is probably better.

WRT paths, MSYS2 can understand windows paths but they need to be quoted, e.g. 'D:/Strawberry/c/bin'. Testing on my machine suggests single and double quotes work the same.

@sisyphus
Copy link

sisyphus commented Oct 5, 2023

MSYS2 can understand windows paths but they need to be quoted, e.g. 'D:/Strawberry/c/bin'

Heh - I always thought the rule would be pretty simple, but I never got around to working out exactly what it was.

For $PATH manipulation from the command line, I find I need to specify the MSYS2 path, as the quotes are apparently ignored:

Owner@DESKTOP-88J497T MINGW64 ~
$ gcc --version
-bash: gcc: command not found

Owner@DESKTOP-88J497T MINGW64 ~
$ export PATH=$PATH:'C:/sp/_64/sp-5.38.0-PDL/c/bin'

Owner@DESKTOP-88J497T MINGW64 ~
$ gcc --version
-bash: gcc: command not found

Owner@DESKTOP-88J497T MINGW64 ~
$ export PATH=$PATH:"C:/sp/_64/sp-5.38.0-PDL/c/bin"

Owner@DESKTOP-88J497T MINGW64 ~
$ gcc --version
-bash: gcc: command not found

Owner@DESKTOP-88J497T MINGW64 ~
$ export PATH=$PATH:/C/sp/_64/sp-5.38.0-PDL/c/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.

Oops - updated to also demonstrate use of single quotes on the command line.

Cheers,
Rob

@shawnlaffan
Copy link
Contributor

as the quotes are apparently ignored

They probably get eaten as they pass through multiple levels of shell or shell commands, not unlike when calling system. Using MSYS2 paths directly would seem therefore to be safest.

@hakonhagland
Copy link
Author

If you can tell me how I can obtain the exact same ImageMagick source as you're using, I'll give it a go.

@sisyphus I am using the github main branch: https://github.com/ImageMagick/ImageMagick

@hakonhagland
Copy link
Author

If the --with-perl argument is only needed for the build then the msys2 provided perl will work. If it is also needed at run time then the Strawberry Perl version is probably better.

@shawnlaffan I believe the perl version is required at runtime also. On linux, when you build XS modules the .so file contains handshake keys that make it impossible to load the module with a different perl version.

@sisyphus
Copy link

sisyphus commented Oct 5, 2023

I am using the github main branch:

Doesn't build straight out of the box for me.
The 'make' step goes along ok for a while, though repeatedly warns:

./MagickCore/utility-private.h:390:27: warning: passing argument 2 of '_wstat64i32' from incompatible pointer type [-Wincompatible-pointer-types]
  390 |    status=wstat(path_wide,attributes);
      |                           ^~~~~~~~~~
      |                           |
      |                           struct _stat64 *
In file included from ./MagickCore/studio.h:66,
                 from coders/wpg.c:41:
C:/sp/_64/sp-5.38.0-PDL/c/x86_64-w64-mingw32/include/sys/stat.h:128:67: note: expected 'struct _stat64i32 *' but argument is of type 'struct _stat64 *'
  128 |   int __cdecl _wstat64i32(const wchar_t *_Name,struct _stat64i32 *_Stat);
      |   

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 <zstd.h>
      |             ^~~~~~~~
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

Digging back into my past, I can see that I had not built the ImageMagick library.
Looks like I had utilized a publicly available ImageMagick-6.9.2 windows library to build Perl-Magick-6.8.9.
(Sorry for the brazen exaggeration ;-)

Cheers,
Rob

@hakonhagland
Copy link
Author

coders/tiff.c:109:13: fatal error: zstd.h: No such file or directory

@sisyphus I created a new issue for building Image::Magick using MSYS2, see #139.

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