You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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
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.
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 singleStartEnd.c
file. I expect that functions fromStartEnd.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 myStartEnd.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 theGHC-Options
section.After
cabal install
a few files are created, in particularHSdll.dll
/HSdll.dll.a
(inhs/
folder). The generated files do not inlude symbols from theStartEnd.c
that was included in thec-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 fromStartEnd.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 thedist/build
directory there is present pair of fileslibHSpunktor-0.1.0.0.a
andlibHSpunktor-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 singlelibHSpunktor-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 callingghc
as described above?simplified project tree:
Link to sources: https://github.com/pawelp7/hsdll
The text was updated successfully, but these errors were encountered: