Resolving GHC 'I found a duplicate definition for symbol …'

前端 未结 1 1587
花落未央
花落未央 2021-02-07 15:44

When running Haskell programs that import several packages like this one:

import Text.Feed.Import 
import Network.HTTP

main = do
        page <- simpleHTTP (         


        
相关标签:
1条回答
  • 2021-02-07 15:55

    Why this error occurs

    This issue is not specific to a single package (e.g. it was described here in relation to Yesod three years ago), but is caused by the different libraries you import (e.g. HTTP and feed) linking to different versions of a single library (this issue occurs only for libraries that export C-style symbols. Their symbol names are not unique. time is one of those packages.).

    As denoted in the error message, the library that causes the issues in this specific case is time-1.4.0.1.

    Diagnosing the exact problem

    First, you need to identify which different versions exist of your library. You can do this by checking the packages using ghc-pkg describe <packagename>, or just take a look into your cabal installation directory (usually ~/.cabal/lib).

    At the time of writing this, the issue was caused by both time-1.4.0.1 and time-1.4.1 being installed. By using ghc-pkg describe I figured out that feed (and only feed, in my case), linked to time-1.4.1 whereas about 100 libraries linked to time-1.4.0.1.

    How to resolve

    Identify the library version (of the library that causes the error, as denoted in the error message) as described above that fewer packages depend on. You'll need to rebuild all packages that depend on it. In my case this is time-1.4.1.

    Then, uninstall the package:

    $ ghc-pkg unregister time-1.4.1 --force 
    unregistering time-1.4.1 would break the following packages: feed-0.3.9.2 (ignoring)
    

    Note that the feed package is now broken and needs to be rebuilt and reinstalled. After rebuilding however, it won't link to time-1.4.1 but time-1.4.0.1 (in my specific case). This re-linking will resolve the duplicate symbol problem.

    $ cabal install feed
    

    If the error still occurs after that, re-check all dependencies as described above. You need to make sure any library you import will show the same library it's linked to when analyzed with ghc-pkg describe <pkg>

    Update: In order to find out, which packages depend on the problematic library, simply use ghc-pkg unregister without the --force flag (Thanks to John J. Camilleri for pointing that out!). Note that if no packages depend on said problematic package, it will be removed.

    0 讨论(0)
提交回复
热议问题