Posted on 2005-10-17 15:11:54-07 by tschnebeck
Problem using WriteInfo
Hi, when using Writer.pl I get this error, when embedding exiftool into C++. I can test later if this also happens with the perl interpreter via perl -e: "You may need to build a new perl executable which either supports dynamic loading or has the Encode module statically linked into it. at /usr/lib/perl5/site_perl/5.8.6/Image/ExifTool/Writer.pl line 124" Bye Thorsten
Direct Responses: 1184 | Write a response
Posted on 2005-10-17 15:50:01-07 by exiftool in response to 1183
Re: Problem using WriteInfo
Hi Thorsten,

I'm not sure why this gives an error while all my other dynamic links work fine (all ExifTool modules are linked dyamically).

I recently added the Encode use (in version 5.67). It fixes a problem if the users passes UTF8-encoded strings via the API, but if you're going through the exiftool script, this isn't a problem. The Encode module should be standard with Perl 5.8 or greater, so I'm surprised you get this error. However, maybe we can avoid this error by wrapping the 'require' in an 'eval'. Try this:

Replace the following lines (124 and 125) in lib/Image/ExifTool/Writer.pl require Encode; Encode::_utf8_off($value); with eval 'require Encode' and Encode::_utf8_off($value);

If this works for you, I'll make this change to the official version.

Direct Responses: 1185 | Write a response
Posted on 2005-10-17 17:00:03-07 by tschnebeck in response to 1184
Re: Problem using WriteInfo
Not better: "Undefined subroutine &Encode::_utf8_off called at /usr/lib/perl5/site_perl/5.8.6/Image/ExifTool/Writer.pl line 125 during global destruction." Looks like my system has not the correct Encode module(?) How can I check, how can I install via cpan? Bye Thorsten
Direct Responses: 1186 | Write a response
Posted on 2005-10-17 17:13:22-07 by exiftool in response to 1185
Re: Problem using WriteInfo
I don't understand how the "eval 'require Encode'" can be successful without Encode::_utf8_off() being available.

If it is calling _utf8_off(), then the Encode module must have been loaded, so you must have it. It doesn't make sense.

The following line WILL work instead, but is slower so I would rather not do this in the official version:

pack('C*', unpack('C*', $value));

So I'm at a bit of a loss trying to get something that works for everyone yet doesn't compromise performance.

Direct Responses: 1187 | Write a response
Posted on 2005-10-17 17:59:28-07 by tschnebeck in response to 1186
Re: Problem using WriteInfo
Hmm, I read a little bit in Usenet but did not find anything helpful. Oh, so said _utf8_off() is evil and a rally bad thing ;-)
pack('C*', unpack('C*', $value)); works - or better it runs - my C++ program still crashs when writing. But this is now my problem :-)

Bye

Thorsten
Direct Responses: 1188 | Write a response
Posted on 2005-10-17 18:11:01-07 by exiftool in response to 1187
Re: Problem using WriteInfo
I know _utf8_off() is evil, but it does the same thing as the unpack/pack and is a LOT faster. :-)

But I think I have figured out a more portable way of doing this which doesn't compromise performance on most systems:

if (eval 'require Encode; Encode::is_utf8($value)' or $@) { $value = pack('C*', unpack('C*', $value)); }

This should work for you because the eval will fail, forcing the data to be repacked. And on systems that support Encode::is_utf8() the data is only repacked if necessary (which is almost never), so it won't slow things down too much. I have updated the my version of ExifTool with this change.

As you may have learned, this whole Perl/Unicode thing can be a bit confusing.

Thanks for your help in sorting this out.

Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.