How to fix libiconv error on Mac?

2019-04-21 20:51发布

问题:

I have uninstall port from Mac with this comand:

sudo port -fp uninstall installed

Then when I use wget to download file,it shows me:

dyld: Library not loaded: /opt/local/lib/libiconv.2.dylib
  Referenced from: /opt/local/bin/wget
  Reason: Incompatible library version: wget requires version 8.0.0 or later, but libiconv.2.dylib provides version 7.0.0
Trace/BPT trap: 5

How to do?

※ Mac OS X 10.7.5

Addition

When I run

otool -L $(which wget)

It gave me

/opt/local/bin/wget:
    /opt/local/lib/libiconv.2.dylib (compatibility version 8.0.0, current version 8.1.0)
    /opt/local/lib/libintl.8.dylib (compatibility version 10.0.0, current version 10.1.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 635.19.0)
    /opt/local/lib/libgnutls.26.dylib (compatibility version 49.0.0, current version 49.3.0)
    /opt/local/lib/libtasn1.3.dylib (compatibility version 5.0.0, current version 5.13.0)
    /opt/local/lib/libgcrypt.11.dylib (compatibility version 19.0.0, current version 19.0.0)
    /opt/local/lib/libgpg-error.0.dylib (compatibility version 9.0.0, current version 9.0.0)
    /opt/local/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.7)
    /opt/local/lib/libidn.11.dylib (compatibility version 18.0.0, current version 18.8.0)

回答1:

Apparently you built and installed a copy of wget locally while you had libiconv installed from MacPorts so it dynamically links to that library which you've now removed. If you want to remove all traces of MacPorts, you'll need to rebuild that copy of wget.

Otherwise, you could install a copy of wget with MacPorts which will also install all dependencies like libiconv.

sudo port selfupdate
sudo port clean wget
sudo port install wget

Or, instead of wget, you could use curl which Apple supplies with OS X.

UPDATE: Based on your update, it appears you are using a MacPorts-installed wget. Somehow you've managed to get the dependencies out of sync. (Why use port -fp uninstall installed ?) Suggest you now try:

sudo port selfupdate     # if not run recently   
sudo port clean libiconv
sudo port upgrade --force libiconv

to force an upgrade of libiconv to the current version.

UPDATE [2014-12]: Revisiting this, the problem may also be due to an incomplete MacPorts port file that doesn't register the wget port dependency on libiconv. I've opened an issue about it. [...] And the MacPorts project answers that this may be a result of not following the MacPorts migration instructions when upgrading to a new release of OS X; there is a MacPorts problem hotlist entry for libiconv compatibilities here.

In any case, what may work is to reinstall wget from source.

sudo port selfupdate
sudo port -f uninstall wget
sudo port -s install wget

If that doesn't help, you may want to read the migration instructions and make sure you've re-installed all your ports after upgrading.