Dyld: Symbol not found: _iconv when using javac to compile on macOS

I just started using Java on my MacOS and I got the following error while compiling my first .java file using javac.

dyld: Symbol not found: _iconv
  Referenced from: /usr/lib/libcups.2.dylib
  Expected in: /opt/local/lib/libiconv.2.dylib
 in /usr/lib/libcups.2.dylib
Trace/BPT trap: 5

      

Can anyone fix the problem?

+3


source to share


1 answer


This is a common problem when using macports and you are setting for a variable DYLD_LIBRARY_PATH

/opt/local/lib

. There are several libraries in macports that can interfere with the system libraries, and when you are on the command line, then programs will not be able to run.

Workarounds do not set the variable for the shell, but this can cause problems with other macports applications running. If you're just working from the command line, you can create functions in .bashrc

that run commands without a variable, for example.

java() 
{ 
    env DYLD_LIBRARY_PATH= java "$@"
}

      



and similar for javac, etc. This will allow you to leave the variable specified, but prevent interference when calling those specific command line tools.

I've moved from macports to homebrew , which is a little better behaved in this regard - it generally refuses to nest things in a way that gets in the way of system libraries without causing the problem - it's a personal choice, although it doesn't recommend you switch.

+3


source







All Articles