If you use a sublibrary for .chs-files and c2hs generates .chs.c-files with __c2hs__wrapped__-functions, then this fails with an error that these symbols cannot be found.
❯ cabal build
Resolving dependencies...
Build profile: -w ghc-9.4.8 -O1
In order, the following will be built (use -v for more details):
- tmp-ifRBXdAUos-0.1.0.0 (lib:tmp-ifRBXdAUos-sub) (first run)
- tmp-ifRBXdAUos-0.1.0.0 (lib) (first run)
- tmp-ifRBXdAUos-0.1.0.0 (exe:tmp-ifRBXdAUos) (first run)
Configuring library 'tmp-ifRBXdAUos-sub' for tmp-ifRBXdAUos-0.1.0.0..
Preprocessing library 'tmp-ifRBXdAUos-sub' for tmp-ifRBXdAUos-0.1.0.0..
Building library 'tmp-ifRBXdAUos-sub' for tmp-ifRBXdAUos-0.1.0.0..
[1 of 1] Compiling MySubLib ( /tmp/tmp.ifRBXdAUos/dist-newstyle/build/x86_64-linux/ghc-9.4.8/tmp-ifRBXdAUos-0.1.0.0/l/tmp-ifRBXdAUos-sub/build/tmp-ifRBXdAUos-sub/MySubLib.hs, /tmp/tmp.ifRBXdAUos/dist-newstyle/build/x86_64-linux/ghc-9.4.8/tmp-ifRBXdAUos-0.1.0.0/l/tmp-ifRBXdAUos-sub/build/tmp-ifRBXdAUos-sub/MySubLib.o, /tmp/tmp.ifRBXdAUos/dist-newstyle/build/x86_64-linux/ghc-9.4.8/tmp-ifRBXdAUos-0.1.0.0/l/tmp-ifRBXdAUos-sub/build/tmp-ifRBXdAUos-sub/MySubLib.dyn_o )
Configuring library for tmp-ifRBXdAUos-0.1.0.0..
Preprocessing library for tmp-ifRBXdAUos-0.1.0.0..
Building library for tmp-ifRBXdAUos-0.1.0.0..
[1 of 1] Compiling MyLib ( src/MyLib.hs, /tmp/tmp.ifRBXdAUos/dist-newstyle/build/x86_64-linux/ghc-9.4.8/tmp-ifRBXdAUos-0.1.0.0/build/MyLib.o, /tmp/tmp.ifRBXdAUos/dist-newstyle/build/x86_64-linux/ghc-9.4.8/tmp-ifRBXdAUos-0.1.0.0/build/MyLib.dyn_o )
Configuring executable 'tmp-ifRBXdAUos' for tmp-ifRBXdAUos-0.1.0.0..
Preprocessing executable 'tmp-ifRBXdAUos' for tmp-ifRBXdAUos-0.1.0.0..
Building executable 'tmp-ifRBXdAUos' for tmp-ifRBXdAUos-0.1.0.0..
[1 of 1] Compiling Main ( app/Main.hs, /tmp/tmp.ifRBXdAUos/dist-newstyle/build/x86_64-linux/ghc-9.4.8/tmp-ifRBXdAUos-0.1.0.0/x/tmp-ifRBXdAUos/build/tmp-ifRBXdAUos/tmp-ifRBXdAUos-tmp/Main.o )
[2 of 2] Linking /tmp/tmp.ifRBXdAUos/dist-newstyle/build/x86_64-linux/ghc-9.4.8/tmp-ifRBXdAUos-0.1.0.0/x/tmp-ifRBXdAUos/build/tmp-ifRBXdAUos/tmp-ifRBXdAUos
/tmp/tmp.ifRBXdAUos/dist-newstyle/build/x86_64-linux/ghc-9.4.8/tmp-ifRBXdAUos-0.1.0.0/build/libHStmp-ifRBXdAUos-0.1.0.0-inplace.a(MyLib.o):function tmpzmifRBXdAUoszm0zi1zi0zi0zminplace_MyLib_someFunc1_info:(.text+0xd7): error: undefined reference to '__c2hs_wrapped__pw_check_library_version'
collect2: error: ld returned 1 exit status
ghc-9.4.8: `gcc' failed in phase `Linker'. (Exit code: 1)
Error: cabal: Failed to build exe:tmp-ifRBXdAUos from tmp-ifRBXdAUos-0.1.0.0.
To Reproduce
Create new project
/tmp
❯ cd $(mktemp -d)
/tmp/tmp.ifRBXdAUos
❯ ghc --version; cabal --version
The Glorious Glasgow Haskell Compilation System, version 9.4.8
cabal-install version 3.10.2.1
compiled using version 3.10.2.1 of the Cabal library
/tmp/tmp.ifRBXdAUos
❯ cabal init --libandexe -nm
[Log] Guessing dependencies...
[Log] Guessing dependencies...
[Log] Using cabal specification: 3.0
[Warning] unknown license type, you must put a copy in LICENSE yourself.
[Log] Creating fresh file CHANGELOG.md...
[Log] Creating fresh directory ./src...
[Log] Creating fresh file src/MyLib.hs...
[Log] Creating fresh directory ./app...
[Log] Creating fresh file app/Main.hs...
[Log] Creating fresh file tmp-ifRBXdAUos.cabal...
[Warning] No synopsis given. You should edit the .cabal file and add one.
[Info] You may want to edit the .cabal file and add a Description field.
Error Description
If you use a sublibrary for .chs-files and c2hs generates .chs.c-files with
__c2hs__wrapped__
-functions, then this fails with an error that these symbols cannot be found.To Reproduce
Edit
./tmp-ifRBXdAUos.cabal
Add
./src-sub/MySubLib.chs
Edit
./src/MyLib.hs
cabal build
Remark
If the sublibrary is removed and everything is moved to the main library, then it works as you would expect.