Skip to content
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

Symbols from c-sources not present in DLL on Windows #2589

Open
pawelp7 opened this issue May 13, 2015 · 3 comments
Open

Symbols from c-sources not present in DLL on Windows #2589

pawelp7 opened this issue May 13, 2015 · 3 comments

Comments

@pawelp7
Copy link

pawelp7 commented May 13, 2015

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

@pawelp7 pawelp7 changed the title Cabal module resulting library does not link with c-sources on Windows Symbols from c-sources not present in DLL on Windows May 13, 2015
@23Skidoo
Copy link
Member

@edsko has been working on making it easier to build DLLs with Cabal (#2540). Maybe he can help you.

@edsko
Copy link
Contributor

edsko commented May 13, 2015

If you check out https://github.com/edsko/cabal/tree/pr/platform-libs you will get native support for building platform libraries in Cabal. The PR is still pending (pinging @dcoutts :) but you should be able to use it right now to build DLLs on Windows. Let me know if it doesn't work for you.

@moll
Copy link

moll commented Mar 24, 2019

I recently stumbled upon an similar issue and narrowed it down to capitalization of the c-source file. It could be related to this. Created #5960.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants