can GHC build an executable from a C source file?

Hi.
I'm checking if it possible to build an executable from C source files only.
As an example:
#include

Works for me without the --make, as `ghc foo.c`
--A
On Tue, Mar 17, 2009 at 6:32 PM, Manlio Perillo
Hi.
I'm checking if it possible to build an executable from C source files only.
As an example:
#include
int main () { printf("hello world\n"); return 0; }
$ghc --make foo.c
However this only produces the object file, foo.o; it does not build the executable file.
What is the reason for this behaviour? I have tested with GHC 6.8.2.
Thanks Manlio _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

You know, I hear theres this brilliant program for compiling C code -- gcd? ccg? gcc, yah gcc... Anyone tried it? In all seriousness though, why do you need to compile c with ghc? I'm curious, it seems a bit pointless... /Joe Manlio Perillo wrote:
Anton Tayanovskyy ha scritto:
Works for me without the --make, as `ghc foo.c`
For me, too, thanks.
Manlio _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Yhc used to do this (when you could still build it). Turns out that on
Windows using gcc that gets installed with ghc isn't particularly fun,
while ghc makes a very pleasant build experience. Something to do with
directory layouts, head file searching, and what is on the %PATH% by
default.
Thanks
Neil
2009/3/17 Joe Fredette
You know, I hear theres this brilliant program for compiling C code -- gcd? ccg? gcc, yah gcc... Anyone tried it?
In all seriousness though, why do you need to compile c with ghc? I'm curious, it seems a bit pointless...
/Joe
Manlio Perillo wrote:
Anton Tayanovskyy ha scritto:
Works for me without the --make, as `ghc foo.c`
For me, too, thanks.
Manlio _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Joe Fredette ha scritto:
You know, I hear theres this brilliant program for compiling C code -- gcd? ccg? gcc, yah gcc... Anyone tried it?
In all seriousness though, why do you need to compile c with ghc? I'm curious, it seems a bit pointless...
It's for a possible extension I'm planning for Cabal. The idea is to add support for "configuration features". A configuration feature is similar to a "configuration flag", but with some important differences. data Feature = Bool | String A feature block: Feature HaveURandom action: execute include-dirs: ... c-sources: features/urandom.c -- other possible properties, as listed in -- "Build information chapter", excluding `buildable` and -- `other-modules` -- The `action` property can have values `compile` (default`) -- or `execute` This means that I'm testing for a feature named "HaveURandom", and the testing requires to compile/build and then execute some code. In this case there is only a C source file that needs to be compiled; this is the reason why I have asked if GHC supports compilation for C source files only, and the creation of an executable. Here I'm asking Cabal to execute the generated program. If the executable returns 0, then HaveURandom will have value `Feature True`; if it returns 1, then HaveURandom will have value `Feature False`. If the executable write something on stdout, then HaveURandom will have value `Feature string`. If compilation fails, HaveURandom will have value `Feature False`. If `action` property is "compile", then a successful compilation will result in HaveURandom having a value of `Feature True`. Regards Manlio
participants (4)
-
Anton Tayanovskyy
-
Joe Fredette
-
Manlio Perillo
-
Neil Mitchell