[Haskell-cafe] Cabal: other-modules necessary?

Oleg Grenrus oleg.grenrus at iki.fi
Fri Sep 16 09:12:04 UTC 2022


Also even locally, when you depend on the library and try to link you'll
get linker errors as omitted modules are not part of linkage.

Write a test-suite for your library, and you'll notice!


For example, if I comment out other-modules in postgresql-simple and try
to run a test-suite named "test"

cabal run test

I'll get (just) a warning when compiling the library

<no location info>: warning: [-Wmissing-home-modules]
    These modules are needed for compilation but not listed in your
.cabal file's other-modules:
        Database.PostgreSQL.Simple.Compat
        Database.PostgreSQL.Simple.HStore.Implementation
        Database.PostgreSQL.Simple.Internal.PQResultUtils
        Database.PostgreSQL.Simple.Time.Implementation
        Database.PostgreSQL.Simple.Time.Internal.Parser
        Database.PostgreSQL.Simple.Time.Internal.Printer
        Database.PostgreSQL.Simple.TypeInfo.Types

but compilation of test-suite fails (it uses TemplateHaskell, otherwise
it probably would fail when linking the executable)

<command line>: can't load .so/.DLL for:
/code/public-haskell/postgresql-simple/dist-newstyle/build/x86_64-linux/ghc-8.6.5/postgresql-simple-0.6.4/build/libHSpostgresql-simple-0.6.4-inplace-ghc8.6.5.so
(/code/public-haskell/postgresql-simple/dist-newstyle/build/x86_64-linux/ghc-8.6.5/postgresql-simple-0.6.4/build/libHSpostgresql-simple-0.6.4-inplace-ghc8.6.5.so:
undefined symbol:
postgresqlzmsimplezm0zi6zi4zminplace_DatabaseziPostgreSQLziSimpleziInternalziPQResultUtils_zdwfinishQueryWith_closure)

What is additionally annoying, is that if your executable doesn't
actually (even transitively) use any symbols from other-modules (which
some test-suites may not), they won't be needed for linking and it will
succeed... until you add something, and linking will fail with
incomprehensible error like above.

- Oleg

On 16.9.2022 11.53, Nicolas Trangez wrote:
> Hello Volker,
>
> Compilation will, indeed, succeed. However, distribution won't: if the
> module is not listed in `Other-Modules` (or any of the other sections),
> it won't be included in the tarball generated when you invoke `cabal
> sdist`, i.e., the source archive uploaded to Hackage.
>
> Hence, if someone then tries to download and build your package from
> Hackage, this will fail, since some module source files are missing.
>
> There may be other effects of not listing some module, though above is
> the one I'm aware of.
>
> Cheers,
>
> Nicolas
>
> On Fri, 2022-09-16 at 10:47 +0200, Volker Wysk wrote:
>> Hi
>>
>> The cabal user guide says (in section 6.2.12): "Every module in the
>> package
>> must be listed in one of other-modules, library:exposed-modules or
>> executable:main-is fields."
>>
>> However, I only get a warning message, when I comment out the other-
>> modules
>> field in my .cabal file. The program compiles. This is the message:
>>
>> <no location info>: warning: [-Wmissing-home-modules]
>>     These modules are needed for compilation but not listed in your
>> .cabal 
>>     file's other-modules: 
>>         Hsskripte Sicherung SicherungAktionen Text Wahl Zeit
>>
>> Is it really necessary to specify all the imported modules? If so,
>> why does
>> the program compile? Can that warning message be turned off?
>>
>> Apart from that, I'm happy with cabal.   :-)
>>
>> Cheers,
>> Volker
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.


More information about the Haskell-Cafe mailing list