-
Notifications
You must be signed in to change notification settings - Fork 26
php-ffi on windows fails to link to g_malloc and g_free #144
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
Comments
This would provide it: https://github.com/GNOME/glib/blob/main/glib/gmem.c ...which reads:
Also concerning |
It's a historical accident -- glib used (10+ years ago) to have its own malloc implementation, and therefore needed its own free. These days they just use the platform malloc (thank goodness). You still need to use the |
I'm not exactly sure if the G stands for GNU or GNOME, |
Hey guys! Could you give me advice how to statically link libvips with glib? |
This commit is also relevant here: kleisauke/net-vips@e04c6b0. I think there are at least 3 ways to solve this (ordered from easy to difficult):
Note that point 2 would break compatibility with the shared Windows builds, plus all libvips bindings based on FFI needs to be updated to avoid Since this is only a issue on Windows, I think point 1 is the most straightforward. I might look into making a PR somewhere tomorrow. |
I just opened PR #146 for this. Any testing would be welcome (especially on Windows 32-bit). |
@kleisauke just tested your PR on x64 Windows (currently I don't have win x86). It works fine! Code:<?php
require_once __DIR__ . '/vendor/autoload.php';
use Jcupitt\Vips;
$paths = [
'C:\Users\user\Pictures\photo_2021-01-15_17-04-50.jpg',
'C:\Users\user\Pictures\Untitled2.png',
'C:\Users\user\Pictures\fox.profile0.8bpc.yuv420.avif',
];
echo "File open test" . PHP_EOL;
foreach ($paths as $path) {
var_dump($path);
$img = file_get_contents($path);
$res = Vips\Image::newFromBuffer($img);
var_dump("{$res->width}x{$res->height}, {$res->format}, {$res->coding}, {$res->interpretation}, {$res->bands}");
}
echo PHP_EOL;
echo "Thumbnail write test" . PHP_EOL;
foreach ($paths as $path) {
var_dump($path);
$filename = pathinfo($path, PATHINFO_FILENAME);
$res = Vips\Image::thumbnail_buffer(file_get_contents($path), 600, [
'size' => 'down',
'export_profile' => 'srgb',
]);
var_dump("{$res->width}x{$res->height}, {$res->format}, {$res->coding}, {$res->interpretation}, {$res->bands}");
$res->writeToFile("thumb_{$filename}.jpg", [
'optimize_coding' => true,
'strip' => true,
'interlace' => true,
'background' => 255,
'Q' => 90,
]);
$res = Vips\Image::thumbnail($path, 600, [
'size' => 'down',
'export_profile' => 'srgb',
]);
$buf = $res->writeToBuffer(".jpg", [
'optimize_coding' => true,
'strip' => true,
'interlace' => true,
'background' => 255,
'Q' => 90,
]);
file_put_contents("thumb2_{$filename}.jpg", $buf);
} Output:
|
Config.php
tries to link tog_malloc
andg_free
(glib functions) in the libvips shared library. This works on linux, since it can resolve indirect dependencies, but maybe windows needs the exact shared library that contains the named function.Experiment with directly linking to glib and gobject.
ruby-vips
does this and seems to work on windows.See: https://stackoverflow.com/questions/72330264/libvips-ffi-use-on-windows-php-cannot-find-glib-functions
The text was updated successfully, but these errors were encountered: