-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lift instance cause Cabal build error: unknown symbol with CFFI but Cabal repl works fine #10651
Comments
FWIW, attempting to build here gets me
And indeed, I can't find |
@geekosaur have you checkout Error_branch? |
I have, and I have the files you show, but that module is misnamed and will not be found by Cabal or ghc on Linux, whose filesystem is case sensitive. (It will work on Windows.) |
This also applies to |
Sorry, but what do u mean by the module is misnamed? |
On a case sensitive filesystem such as Linux uses, the filename must match the case of the module name. The files must be named |
That's interesting. I test it in WSL Ubuntu, and it doesn't complain about that. |
I expect it's still using the NTFS filesystem underneath so you can share files between it and Windows programs. I'm running on Linux ext4, which does care. |
@geekosaur are u able to reproduce the same error with cabal 3.12? |
Yes, which makes me think it's not Cabal involved at all; it's more likely something about runtime linking for TH in GHC. I'm trying with ghc-9.8.4 now. |
That's really strange for me. As I think that for cabal repl to work, it must build library successfully and then load it into ghci. So if cabal build fail, the cabal repl also doesn't work. |
Looking back, actually it seems to be the system linker vs. the runtime linker, and the runtime linker (which is custom code used by ghci, unrelated to the system linker) is doing something correctly that the system linker isn't. I failed to build with ghc-9.8.4, with an error in |
Okay, |
@geekosaur yeah, from their github: https://github.com/clash-lang/clash-compiler . They currently only support up to ghc 9.8 version. |
Same error with ghc-9.6.6. I think this is still clearly a GHC issue, or possibly a bug in how |
Well, I am using hmpfr version 0.4.5 cloning directly from this: https://github.com/michalkonecny/hmpfr . It can build library successfully though. Some how I cannot installed it with cabal for my library so I include all of the files from hmpfr to my library. |
I should mention that ghci may use different glue libraries than ghc itself does, although I don't see I'm also not seeing In any case, it's past 23:00 here and I'm heading to bed. I would pursue this with the ghc folks. |
That suggests you're doing it incorrectly and it's not finding the right library as a result. |
@geekosaur , I have test with ghc 9.10.1 on Linux WSL. It works and uses clash-prelude-1.9 and clash-lib-1.9. However, I have to remove the constrain of the base by removing gcc -c cbits/chsmpfr.c -o cbits/chsmpfr.o
cabal build --ghc-options cbits/chsmpfr.o Now, I don't have any undefined symbol error with mpfr_custom_get_size_wrap defined in my chsmpfr.c file but instead I get undefined error with mpfr_set_str function which is the part of MPFR library.
It is interesting that when I look at the /tmp/ghc556850_0, I see 2 dynamic shared libraries libghc_1.so and lib_ghc101.so . This doesn't happen if I don't include the object file when building with cabal. |
Those are generated internally by ghc as part of compiling, and aren't under cabal's control. One of them is probably an FFI stub, which it probabaly doesn't make if it can't find the object or library being used via FFI, but you'd have to ask the GHC folks. |
Describe the bug
When building a Haskell-based Floating Point library for Clash that uses the mpfr library through the hmpfr binding, an error occurs during the cabal build process on both Windows and Linux. On Windows, the error indicates an unknown symbol (mpfr_add) from MPFR library, while on Linux, the error involves an undefined symbol (mpfr_custom_get_size_wrap) located in the chsmpfr.c file in cbits folder, preventing successful compilation. However, running cabal repl works fine without issues on both platforms.
To Reproduce
Steps to reproduce the behavior:
On Window with msys2:
On Linux Ubuntu WSL
Window:
Linux
Expected behavior
The expected behavior is for the cabal build to compile the project successfully without any unknown symbol errors related to mpfr_add on Windows or mpfr_custom_get_size_wrap on Linux. If the cabal build fail, then cabal repl shouldn't work. But this case doesn't happen.
System information
cabal 3.10.3
,ghc 9.8.2
versions,gcc 11.4
in WSLAdditional context
I am building a floating point library for Clash that uses FloPoCo, a floating point core generator. The library uses the FloPoCo floating point format, defined as FoFloat, and integrates with the MPFR library via the hmpfr Haskell bindings. The goal is to provide accurate floating-point operations in Clash-generated HDL code by simulating the floating-point operations in software.
The following code causes the error during the build process:
The issue occurs during the cabal build step when compiling the FloPoCoFloat library.
Despite these errors, the cabal repl command works as expected on both platforms and successfully loads the proto.hs file located in src folder.
The error appears to be related to the interaction between the hmpfr Haskell bindings and the C-based MPFR library, with missing or improperly linked symbols.
The issue is consistent across both platforms but manifests with different symbols.
GitHub repository with error branch: FloPoCoFloat - Error_branch
The text was updated successfully, but these errors were encountered: