#5025: GHC should support -x objective-c
---------------------------------+------------------------------------------
Reporter: guest | Owner:
Type: feature request | Status: new
Priority: normal | Component: Compiler
Version: 7.0.2 | Keywords: objective-c
Testcase: | Blockedby:
Os: MacOS X | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
On OSX, gcc accepts .m files as objective-c source. It can even trivially
compile .c and .m files in the same program or library.
Unfortunately, ghc treats .m files as input to the linker step. GHC
supports -x as a means of saying what language a file is, except that
unlike gcc it lacks support for "objective-c". For example, if I told
ghc, `-x c foo.my-c`, then ghc would invoke gcc as `gcc -x c foo.my-c` and
gcc would then treat foo.my-c as C source code.
Cabal gives all C files to ghc and lets ghc invoke gcc. This means that
specifying objective-c files as "c-sources" results in GHC complaining
about linker input. Even setting `-pgmc` is not sufficient to trick
cabal. I spent several hours trying everything I could think of here to
trick cabal, like setting my PATH and write wrapper scripts for gcc, but
it seems that cabal always hands these files to ghc first.
Therefore, I propose that GHC adds support for `-x objective-c foo.m`.
Even better would be for GHC to accept .m files on OSX without the extra
-x flag. The new -x flag would be sufficient to write .cabal files that
use objective-c to get access to OSX specific APIs, much like C can be
used on other platforms.
I think even if cabal adds an "objective-c-sources" line in the .cabal
file that the above solution is a nice-to-have for ghc. I also hope that
it is super easy to implement, but I haven't looked at the ghc sources to
see if that's the case.
Here is the relevant section of the gcc manpage
http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/gcc.1.html:
{{{
You can specify the input language explicitly with the -x option:
-x language
Specify explicitly the language for the following input files
(rather than letting the compiler
choose a default based on the file name suffix). This option
applies to all following input
files until the next -x option. Possible values for language
are:
c c-header c-cpp-output
c++ c++-header c++-cpp-output
objective-c objective-c-header objective-c-cpp-output
objective-c++ objective-c++-header objective-c++-cpp-
output
assembler assembler-with-cpp
ada
f95 f95-cpp-input
java
treelang
-x none
Turn off any specification of a language, so that subsequent
files are handled according to their
file name suffixes (as they are if -x has not been used at
all).
}}}
Having ghc support all of gcc -x flags would make me super happy!
Unfortunately, I found that the order you pass -x to gcc matters (it must
be passed before the corresponding input files are specified), and when I
added "-optc-x -optcobjective-c" to the ghc commandline I found that it
passed the -x flag too late.
Thanks!
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5025>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs