1

The proprietary software Stata version 14 works fine on LTS 16.04, but I made the mistake of upgrading Ubuntu to 16.10 without thinking about the possibility that proprietary software (Stata is my only one) might break. I can't downgrade. Stata says:

stata-se: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory

Stata support tells me to install libpng12.

So my question is, how can I safely install and make this library available to Stata? (Apparently, the Stata GUI won't work perfectly even with the library, but the functionality will be available.)

Trying with apt gives:

E: Unable to locate package libpng12

libpng-dev is already installed, and seems not to fit the need.

I assume Stata support would have told me if an easy fix like this would work, but in trying to fake it with symlinks,

sudo ln -s /usr/lib/i386-linux-gnu/libpng16.so.16.25.0 /usr/lib/i386-linux-gnu/libpng12.so.0

made no difference.

sudo ln -s /usr/lib/i386-linux-gnu/libpng16.so.16.25.0 /usr/lib/x86_64-linux-gnu/libpng12.so.0

gave:

stata-se: error while loading shared libraries: libpng12.so.0: wrong ELF class: ELFCLASS32
  • Have you tried installing libpng-dev? For 16.10 it's libpng16.so but it might be backwards compatible. – Elder Geek Apr 5 '17 at 16:40
  • Yes; it's already installed, and no good. (Question updated; thanks) – CPBL Apr 5 '17 at 16:59
  • Did you by any chance try making a symlink 12-->16? A bit of a long shot but it might work. – Elder Geek Apr 5 '17 at 17:07
  • ` locate libpng16.so.0` gives me nothing, so I'm not sure where it should go. There are: /usr/lib/i386-linux-gnu/libpng16.so.16 /usr/lib/i386-linux-gnu/libpng16.so.16.25.0 /usr/lib/x86_64-linux-gnu/libpng16.so /usr/lib/x86_64-linux-gnu/libpng16.so.16 /usr/lib/x86_64-linux-gnu/libpng16.so.16.25.0 – CPBL Apr 5 '17 at 17:23
  • 1
    I wish I had a solution for you. Looking at this and your error makes me wonder if there's a mismatch between the 32 and 64 bit that is having an impact on your problem. – Elder Geek Apr 5 '17 at 17:36
2

Your symlinks won't work because you're creating a link to a i386 library in a path that is commonly searched for amd64 libraries. Executables compiled for one architecture (amd64) can't load shared libraries compiled for another architecture (i386).

You may be able to trick Stata to use libpng16 instead of libpng12 if you ensure that it's for the same architecture as the Stata executable itself. I’ll assume that the latter is for amd64 (considering that the error message complains about an invalid ELF class ELFCLASS32 which is used for i386 instruction sets only).

It looks like Stata explicitly checks the libpng version, so the trick described above and thus the two solutions building upon it below won't work. Refer to the Better Solution instead.

Quick and dirty solution

Masquerade libpng16.so.16 as libpng12.so.0 to all amd64 executables:

sudo ln -sfT libpng16.so.16 /usr/lib/x86_64-linux-gnu/libpng12.so.0

Still dirty but with fewer future surprises

Masquerade libpng16.so.16 as libpng12.so.0 to selected executables only (thus eliminating the risk that another applications picks up the bogus libpng12.so.0 by mistake):

  1. Create a directory for “masquerade” shared libraries, e. g.:

    sudo mkdir -p /usr/local/lib/stata/shared-library-hack
    
  2. Place a symbolic link to the masked shared library into it:

    sudo ln -s /usr/lib/x86_64-linux-gnu/libpng16.so.16 /usr/local/lib/stata/shared-library-hack/libpng12.so.0
    
  3. Run the program with a modified library search path:

    LD_LIBRARY_PATH=/usr/local/lib/stata/shared-library-hack [COMMAND] [ARGUMENTS...]
    

    Or if you want to retain potentially existing alterations to the library search path:

    LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+"${LD_LIBRARY_PATH}:"}/usr/local/lib/stata/shared-library-hack" [COMMAND] [ARGUMENTS...]
    

    If you don't want to type such a long command each time you start such an application, you can either use a shell script wrapper or edit the application starter description (i. e. the Exec= stanza in the .desktop file) accordingly.

Better solution

Actually install libpng12.so.0. The easiest way is to download and install the Deb package of an earlier Ubuntu release:

  1. Go to https://packages.ubuntu.com/xenial/amd64/libpng12-0/download, pick a mirror and download the package archive.

  2. Use your favourite package manager to install the package archive.

    On the command line you can use:

    sudo apt install [DOWNLOAD-PATH]/libpng12-0_*_amd64.deb
    

    (Replace [DOWNLOAD-PATH] with whichever path you used as the target directory of the download earlier.)

This is not a proper solution, because updates to libpng12, including security updates, will not be automatically installed, so doing this introduces a security risk. – fkraiem Dec 8 '17 at 4:36

| improve this answer | |
  • Under 17.04: Your "quick and dirty" results in: "stata: /usr/lib/x86_64-linux-gnu/libpng12.so.0: version `PNG12_0' not found (required by stata)" – CPBL Aug 31 '17 at 21:12
  • ... I then tried your "Proper solution" and stata now launches under 17.04. The icons are missing, but everything else seems to work fine. Thanks! – CPBL Aug 31 '17 at 21:20
  • Thanks for the feedback! Looks like Stata explicitly checks the libpng version. I adjusted my answer accordingly. – David Foerster Aug 31 '17 at 23:54
  • This is not a proper solution, because updates to libpng12, including security updates, will not be automatically installed, so doing this introduces a security risk. – fkraiem Dec 8 '17 at 4:36
-1

Here is the simpler/compact answer:

This is tested for 64bit Stata on a 64bit Ubuntu 16.10 and 17.10 (but seems to fail on 17.04?). Simply:

visit http://packages.ubuntu.com/xenial/amd64/libpng12-0/download and click on any of the links to mirrors there. This will download libpng12-0_1.2.54-1ubuntu1_amd64.deb. Click on this file, or launch it with something like

gnome-open ~/Downloads/libpng12-0_1.2.54-1ubuntu1_amd64.deb

and click the install button.

Now Stata14 and its xstata will launch fine. The icons will be missing in the menus, but everything else seems to work fine.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.