Opened 5 months ago

Last modified 5 months ago

#61222 assigned defect

ghc @8.10.1: testing fails because the symbol _iconv is not found

Reported by: ryandesign (Ryan Schmidt) Owned by: essandess (Steve Smith)
Priority: Normal Milestone:
Component: ports Version: 2.6.3
Keywords: Cc:
Port: ghc


Running sudo port test ghc fails:

:info:test Linking mk/ghc-config ...
:info:test Undefined symbols for architecture x86_64:
:info:test   "_iconv", referenced from:
:info:test       _hs_iconv in libHSbase-

This was previously mentioned in #57821 but needs to be tracked as a separate issue.

It is difficult to say why this happens, since it does not show us how it is "Linking mk/ghc-config". Is there a way to turn off silent rules so that we see the link command?

The problem may be that it is not using -liconv when linking, or that it is not using -L/opt/local/lib when linking (and in any case, the port needs to declare a dependency on port:libiconv as mentioned in #60171), or that libHSbase- has been built against /usr/lib/libiconv.dylib whereas the test is now trying to link against /opt/local/lib/libiconv.dylib (in which case, fix libHSbase- so that it is linked against /opt/local/lib/libiconv.dylib or use libHSbase- instead of libHSbase-

Attachments (1)

main.log (13.0 KB) - added by ryandesign (Ryan Schmidt) 5 months ago.

Download all attachments as: .zip

Change History (7)

Changed 5 months ago by ryandesign (Ryan Schmidt)

Attachment: main.log added

comment:1 Changed 5 months ago by essandess (Steve Smith)

This is an old, well-known, and annoying problem with ghc when there are multiple iconv libraries installed. I've looked for and haven't been able to identify the actual fix, which preferably would be to make the build completely dependent on native /usr/lib/libiconv.dylib, or the port libiconv.

If MacPorts's libiconv is installed, the simple solution is to run

sudo port deactivate libiconv

before running sudo port test ghc, then re-activating after you're done.

In ghc's Portfile, all the obvious things I and others have tried appear not to work, e.g. specifying LIBRARY_PATH so that the build finds /opt/local/lib/libiconv.dylib.

See also:

Last edited 5 months ago by ryandesign (Ryan Schmidt) (previous) (diff)

comment:3 Changed 5 months ago by ryandesign (Ryan Schmidt)

You mentioned that

ghc must be bootstrapped from a pre-compiled binary

and I see that the binary distribution contains libraries/base/dist-install/build/libHSbase-, so I now assume that that is the library mentioned in the error message. I had originally assumed that it was a library that had been built on the user's system. But if it's a library distributed from upstream, then it is logical to assume that it was built with macOS libiconv, not MacPorts libiconv, and that using that library would therefore require that we use macOS libiconv, not MacPorts libiconv.

Again, we need to see the command that the build system is using when it is "Linking mk/ghc-config" so that we can see where in the source code it is happening so that we can change it. For example, if it is linking with libiconv using -L/opt/local/lib -liconv, then it needs to be changed to /usr/lib/libiconv.dylib.

comment:4 Changed 5 months ago by kencu (Ken)

Of the 1% of people who ever try to build ghc against a non-system-installed libiconv, probably 99% of those will be building it against a libiconv installed into /usr/local where the compiler and system find it automatically, and so they would never see this error.

MacPorts building in /opt/local, and in particular this libiconv failure, which as Josh pointed out one time appears to have been specifically designed to flag this problem, are great at demonstrating tiny build issues even with very mature and advanced software projects like ghc.

The ghc build system is quite complex, as I found building ghc for SnowLeopard. Some useful resources:



comment:6 Changed 5 months ago by essandess (Steve Smith)

In ab891551d4693be90aa6492b0f4e5b8d98cebf29/macports-ports (master):

ghc: Bugfixes for test and iconv linking


Note: See TracTickets for help on using tickets.