
I have a very complex project that has to play nice with a lot of C code written by other people. My own code is half Haskell and half C. My build process is rather complex since I generate about 5 different libraries, some of them export Haskell routines. A supreme effort was made to try to make Haskell somewhat invisible, although ultimately it requires a lot of gcc command line work with a bunch of undefines and a links to Haskell static libraries. In the end I'm not sure if it's such a good idea and probably would be better off completing the final link stage just using ghc. In the process of doing all this I attempted to link one of my libraries to some test code written in Haskell and I proceeded to get a few unresolved links whilst running ghc. What happened is that I have a Haskell binary, lets say called foo.o generated from foo.hs that appears in two libraries say called libmyh.a and libmyc.a and that contains a Haskell function called bar. Library libmyh.a ultimately gets built using cabal and libmyc.a gets built using gcc directly. The binary is compiled twice (for complicated reasons) prior to linking to each library. However in the library libmyh.a, the bar symbol is prepended with an ascii string that contains the library name (say libmyh). However the other library shows that the symbol does not have this name decoration since it was linked directly with gcc. It appears however when trying to link against libmyc.a that ghc expects to see the original name decoration for bar. I presume this is due to some side information, perhaps what's contained in foo.hi that informs ghc what names to actually link to. I now ask the question, how can I control this process? Build tools such as CMake and Cabal seem to have their own ideas about what directories to place binaries. It seems like I need to somehow make sure that all files related to the compilation process of a given library are isolated in the same directory or something. Thus it's not enough to specify binaries on the command line of ghc, it's got to have access to some other files; I presume the .hi files. This makes things a bit confusing I'm afraid. -- View this message in context: http://www.nabble.com/Name-Decoration-and-Undefined-References-tf4003458.htm... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

SevenThunders wrote:
perhaps what's contained in foo.hi that informs ghc what names to actually link to.
I'm not so sure if this is correct or not. The truth is I have no .hi files in the directory I try to link my test code, and yet it's somehow finding them in the cabal created distribution directory even though I'm not using cabal for linking the test code. It's pretty baffling to me at this point. -- View this message in context: http://www.nabble.com/Name-Decoration-and-Undefined-References-tf4003458.htm... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

Hello SevenThunders, Saturday, June 30, 2007, 7:45:57 AM, you wrote:
My own code is half Haskell and half C. My build process is rather complex
i have the same. initially C code was compiled by gcc but finally i switched to ghc-only compilation. it's also important to use the same gcc for compiling both Haskell and C code (and using GHC as driver solves this problem, of course). i use make to control compilation of C code. you can download my program as http://www.haskell.org/bz/FreeArc-sources.tar.gz -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

Bulat Ziganshin-2 wrote:
Hello SevenThunders,
Saturday, June 30, 2007, 7:45:57 AM, you wrote:
My own code is half Haskell and half C. My build process is rather complex
i have the same. initially C code was compiled by gcc but finally i switched to ghc-only compilation. it's also important to use the same gcc for compiling both Haskell and C code (and using GHC as driver solves this problem, of course). i use make to control compilation of C code. you can download my program as http://www.haskell.org/bz/FreeArc-sources.tar.gz
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Yes, I'm in the process of migrating to ghc wherever possible. For my little problem, I solved it by copying both the object code (.o files) and the interface files (.hi files) to the source directory from the object file directory created by cabal specifically for building one of my libraries. That object code in turn was linked by gcc into another library (foo) with some external C code. Then to link against foo in Haskell I make sure it's compiled with all the .hi files that had been moved to the source directory. Thus you have to control the files for a given build context and keep them all together, prior to actually using any libraries or object files built with that code. You can't just bring in a different object file during a previous or different link using ghc. Unfortunately it's easy enough to forget where your .hi files came from. -- View this message in context: http://www.nabble.com/Name-Decoration-and-Undefined-References-tf4003458.htm... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
participants (2)
-
Bulat Ziganshin
-
SevenThunders