Symbols from c-sources not present in DLL on Windows
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
Hi,
I want to create a dynamic library from my Haskell program. However, I'm not able to get it to build correctly using cabal on Windows (x64).
As a starting point I used the sample provided by the official GHC documentation: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/win32-dlls.html
In short, I have cabal project containing of a single `Punktor.hs` file and a single `StartEnd.c` file. I expect that functions from `StartEnd.c` file will be accessible in the generated `.dll` library and its imports library (`.a`) as well.
When I compile all files manually by invoking `ghc` this solution just works! I've executed following commands:
- `ghc -c Punktor.hs`
- `ghc -c StartEnd.c`
- `ghc -shared Punktor.o StartEnd.o`
which gave me `.dll` file (along with the `.a`) with symbols from my `StartEnd.c` file as expected.
I'm not able to get the same results using the cabal project and invoking `cabal install`. I have added `-shared` to the `GHC-Options` section.
After `cabal install` a few files are created, in particular `HSdll.dll`/`HSdll.dll.a` (in `hs/` folder). The generated files do not inlude symbols from the `StartEnd.c` that was included in the `c-sources` section of the `.cabal` file.
I am able to use that files to link the library with my C++ program and call Haskell functions (that were exposed with `foreign export`) but not the helper functions from `StartEnd.c`.
I have tried the same thing on Linux. The `cabal install` outputs just a single `.so` file (with no separate import library) that misses the symbols from `.c` file (same problem as on Windows). However, in the `dist/build` directory there is present pair of files `libHSpunktor-0.1.0.0.a` and `libHSpunktor-0.1.0.0-ghc7.8.4.so`. These files are correct (contain needed symbols) and I'm able to call them from my separate C++ project (what is the point). Interestingly, on Windows in said location there is just a single `libHSpunktor-0.1.0.0.a` file that is not usable with MS linker (is this just a static library version of the package?).
The difference might be caused by adding the `-dynamic` option on Linux, not sure about that -- just mentioning it in case it is relevant.
So the question is: why does `StartEnd.c` file is not linked into the generated library?
Is there any way to make it linked using `cabal` -- to achieve same result as by manually calling `ghc` as described above?
simplified project tree:
```
|-- cpp
| |-- main.cpp
`-- hs
|-- punktor.cabal
|-- Setup.hs
`-- src
|-- Punktor.hs
`-- StartEnd.c
```
Link to sources: https://github.com/pawelp7/hsdll
Contributor guide
Assessment
This issue has not been assessed yet.