Re: [Haskell-cafe] more problems with c2hs

On Fri, 2007-04-13 at 02:37 +1000, Ruben Zilibowitz wrote:
Hi,
I've built and installed c2hs on my Mac OS X system now. I read through the research paper on c2hs available on the website for c2hs and decided I would need to try it out to learn it. But it gives me errors which I am having trouble trying to understand. Here are the error messages:
c2hs file.chs
powerpc-apple-darwin8-gcc-4.0.1: c: No such file or directory powerpc-apple-darwin8-gcc-4.0.1: c: No such file or directory powerpc-apple-darwin8-gcc-4.0.1: warning: '-x -x' after last input file has no effect powerpc-apple-darwin8-gcc-4.0.1: no input files c2hs: Error during preprocessing custom header file
c2hs runs cpp -x c ${header} for the header file you specify. You can either specify a header file on the commend line or use #include's in the .chs file. c2hs should generate a .h file itself in that case but it looks like it isn't for some reason. You can find out what it is really doing by running: c2hs --dump trace file.chs btw, the better mailing list for this stuff is the c2hs mailing list: c2hs@haskell.org Duncan

Thanks for pointing to the appropriate mailing list. This is what appears to be happening. file.chs has a line: #include "file.h" After running: c2hs file.chs file.h gets modified so that it contains just: #include "file.h" So I lose the contents of file.h every time I run c2hs! Running cpp - x c file.h by itself doesn't have that effect so the problem must be caused by c2hs somehow. What is wrong with my c2hs? Perhaps the darcs version has some bugs in it. Ruben On 13/04/2007, at 9:01 AM, Duncan Coutts wrote:
On Fri, 2007-04-13 at 02:37 +1000, Ruben Zilibowitz wrote:
Hi,
I've built and installed c2hs on my Mac OS X system now. I read through the research paper on c2hs available on the website for c2hs and decided I would need to try it out to learn it. But it gives me errors which I am having trouble trying to understand. Here are the error messages:
c2hs file.chs
powerpc-apple-darwin8-gcc-4.0.1: c: No such file or directory powerpc-apple-darwin8-gcc-4.0.1: c: No such file or directory powerpc-apple-darwin8-gcc-4.0.1: warning: '-x -x' after last input file has no effect powerpc-apple-darwin8-gcc-4.0.1: no input files c2hs: Error during preprocessing custom header file
c2hs runs cpp -x c ${header}
for the header file you specify. You can either specify a header file on the commend line or use #include's in the .chs file. c2hs should generate a .h file itself in that case but it looks like it isn't for some reason. You can find out what it is really doing by running:
c2hs --dump trace file.chs
btw, the better mailing list for this stuff is the c2hs mailing list: c2hs@haskell.org
Duncan

On Fri, 2007-04-13 at 09:49 +1000, Ruben Zilibowitz wrote:
Thanks for pointing to the appropriate mailing list. This is what appears to be happening. file.chs has a line: #include "file.h" After running: c2hs file.chs file.h gets modified so that it contains just: #include "file.h"
So I lose the contents of file.h every time I run c2hs!
Yes, this file is generated by c2hs from the things you put in the .chs file (like #include and other cpp stuff, #if and the like). So you can't modify that .h file yourself. Also, you cannot #include "file.h" inside "file.chs" because that'll generate a "file.h" file that recursively #includes itself! Personally, I think it's very bad behaviour that the file is called the same as the .chs file but with a .h extension, since this is exactly the name of a file that many people will want to include. I intend to change it to use file.chs.h or something similar that will not clash. (Also I'd like to not generate any .chs.h file in the common case of just #including a single .h file.) Duncan

Oh, right. I see now. I have renamed file.chs to fileInterface.chs. And left the line #include "file.h" in there. But c2hs fileInterface.chs still gives me errors: Attempting to read file `fileInterface.chs'... ...parsing `fileInterface'... ...successfully loaded `fileInterface'. Invoking cpp as `cpp -x c fileInterface.h > fileInterface.i'... powerpc-apple-darwin8-gcc-4.0.1: c: No such file or directory powerpc-apple-darwin8-gcc-4.0.1: c: No such file or directory powerpc-apple-darwin8-gcc-4.0.1: warning: '-x -x' after last input file has no effect powerpc-apple-darwin8-gcc-4.0.1: no input files c2hs: Error during preprocessing custom header file It seems that cpp isn't happy with: cpp -x c fileInterface.h. It complains about the -x c option. Perhaps this is a bug in the Mac OS X version of cpp. Any ideas? Ruben On 13/04/2007, at 10:04 AM, Duncan Coutts wrote:
On Fri, 2007-04-13 at 09:49 +1000, Ruben Zilibowitz wrote:
Thanks for pointing to the appropriate mailing list. This is what appears to be happening. file.chs has a line: #include "file.h" After running: c2hs file.chs file.h gets modified so that it contains just: #include "file.h"
So I lose the contents of file.h every time I run c2hs!
Yes, this file is generated by c2hs from the things you put in the .chs file (like #include and other cpp stuff, #if and the like).
So you can't modify that .h file yourself. Also, you cannot #include "file.h" inside "file.chs" because that'll generate a "file.h" file that recursively #includes itself!
Personally, I think it's very bad behaviour that the file is called the same as the .chs file but with a .h extension, since this is exactly the name of a file that many people will want to include. I intend to change it to use file.chs.h or something similar that will not clash. (Also I'd like to not generate any .chs.h file in the common case of just #including a single .h file.)
Duncan

On Fri, 2007-04-13 at 10:17 +1000, Ruben Zilibowitz wrote:
Oh, right. I see now. I have renamed file.chs to fileInterface.chs. And left the line #include "file.h" in there. But c2hs fileInterface.chs still gives me errors:
Attempting to read file `fileInterface.chs'... ...parsing `fileInterface'... ...successfully loaded `fileInterface'. Invoking cpp as `cpp -x c fileInterface.h > fileInterface.i'... powerpc-apple-darwin8-gcc-4.0.1: c: No such file or directory powerpc-apple-darwin8-gcc-4.0.1: c: No such file or directory powerpc-apple-darwin8-gcc-4.0.1: warning: '-x -x' after last input file has no effect powerpc-apple-darwin8-gcc-4.0.1: no input files c2hs: Error during preprocessing custom header file
It seems that cpp isn't happy with: cpp -x c fileInterface.h. It complains about the -x c option. Perhaps this is a bug in the Mac OS X version of cpp. Any ideas?
Ok, try these from the command line and tell us which work: 1. cpp -x -c fileInterface.h > fileInterface.i 2. cpp -x -c fileInterface.h -o fileInterface.i 3. cpp fileInterface.h -x -c > fileInterface.i 4. cpp fileInterface.h > fileInterface.i 5. gcc -x -c -E fileInterface.h > fileInterface.i 6. gcc -E fileInterface.h > fileInterface.i Perhaps also look in the cpp man page to see if there is anything funny about the -x option on OSX. The reason we need the -x c is to tell cpp that this file is a c file despite the fact that it ends in .h. The same applies to gcc -E. For example if you find gcc -E -x -c works then you can use that: c2hs --cpp='gcc -E' file.chs Duncan

All these seemed to work except for 2. In the c2hs output it says: cpp -x c ... not: cpp -x -c ... I think that might be a key issue. Ruben On 13/04/2007, at 10:40 AM, Duncan Coutts wrote:
On Fri, 2007-04-13 at 10:17 +1000, Ruben Zilibowitz wrote:
Oh, right. I see now. I have renamed file.chs to fileInterface.chs. And left the line #include "file.h" in there. But c2hs fileInterface.chs still gives me errors:
Attempting to read file `fileInterface.chs'... ...parsing `fileInterface'... ...successfully loaded `fileInterface'. Invoking cpp as `cpp -x c fileInterface.h > fileInterface.i'... powerpc-apple-darwin8-gcc-4.0.1: c: No such file or directory powerpc-apple-darwin8-gcc-4.0.1: c: No such file or directory powerpc-apple-darwin8-gcc-4.0.1: warning: '-x -x' after last input file has no effect powerpc-apple-darwin8-gcc-4.0.1: no input files c2hs: Error during preprocessing custom header file
It seems that cpp isn't happy with: cpp -x c fileInterface.h. It complains about the -x c option. Perhaps this is a bug in the Mac OS X version of cpp. Any ideas?
Ok, try these from the command line and tell us which work:
1. cpp -x -c fileInterface.h > fileInterface.i
2. cpp -x -c fileInterface.h -o fileInterface.i
3. cpp fileInterface.h -x -c > fileInterface.i
4. cpp fileInterface.h > fileInterface.i
5. gcc -x -c -E fileInterface.h > fileInterface.i
6. gcc -E fileInterface.h > fileInterface.i
Perhaps also look in the cpp man page to see if there is anything funny about the -x option on OSX.
The reason we need the -x c is to tell cpp that this file is a c file despite the fact that it ends in .h. The same applies to gcc -E.
For example if you find gcc -E -x -c works then you can use that: c2hs --cpp='gcc -E' file.chs
Duncan

On Fri, 2007-04-13 at 11:09 +1000, Ruben Zilibowitz wrote:
All these seemed to work except for 2. In the c2hs output it says: cpp -x c ... not: cpp -x -c ... I think that might be a key issue.
Doh! That was my mistake. :-) It really should be "-x c" not "-x -c". The latter means something totally different :-) Sorry, could you try again with my mistake corrected. Here's an excerpt from the cpp man page on my system: -x c -x c++ -x objective-c -x assembler-with-cpp Specify the source language: C, C++, Objective-C, or assembly. This has nothing to do with standards conformance or extensions; it merely selects which base syntax to expect. If you give none of these options, cpp will deduce the language from the extension of the source file: .c, .cc, .m, or .S. Some other common extensions for C++ and assembly are also recognized. If cpp does not recognize the extension, it will treat the file as C; this is the most generic mode. I thought this -x c feature was portable, where as relying on cpp to default to C mode for a .h file seems much less so. Perhaps we should just spit out a .c file instead of a .h file. It wouldn't make much difference to c2hs as far as I can see. Duncan

I tried all the cpp commands you gave me with -x c instead of -x -c and none of them worked except for the one which had no -x c. It seems like a bug with cpp on Mac OS X. The man page also has the bit you quoted on my system too. Might ask about it on one of the apple mailing lists. Ruben On 13/04/2007, at 12:01 PM, Duncan Coutts wrote:
On Fri, 2007-04-13 at 11:09 +1000, Ruben Zilibowitz wrote:
All these seemed to work except for 2. In the c2hs output it says: cpp -x c ... not: cpp -x -c ... I think that might be a key issue.
Doh! That was my mistake. :-) It really should be "-x c" not "-x -c". The latter means something totally different :-)
Sorry, could you try again with my mistake corrected.
Here's an excerpt from the cpp man page on my system:
-x c -x c++ -x objective-c -x assembler-with-cpp Specify the source language: C, C++, Objective-C, or assembly. This has nothing to do with standards conformance or extensions; it merely selects which base syntax to expect. If you give none of these options, cpp will deduce the language from the extension of the source file: .c, .cc, .m, or .S. Some other common extensions for C++ and assembly are also recognized. If cpp does not recognize the extension, it will treat the file as C; this is the most generic mode.
I thought this -x c feature was portable, where as relying on cpp to default to C mode for a .h file seems much less so. Perhaps we should just spit out a .c file instead of a .h file. It wouldn't make much difference to c2hs as far as I can see.
Duncan

This seems to work on my system: gcc -E -x c myheader.h An odd thing I noticed about cpp is that it appears to be a wrapper for gcc on Darwin: cpp --version powerpc-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5367) Copyright (C) 2005 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Ruben On 13/04/2007, at 12:01 PM, Duncan Coutts wrote:
On Fri, 2007-04-13 at 11:09 +1000, Ruben Zilibowitz wrote:
All these seemed to work except for 2. In the c2hs output it says: cpp -x c ... not: cpp -x -c ... I think that might be a key issue.
Doh! That was my mistake. :-) It really should be "-x c" not "-x -c". The latter means something totally different :-)
Sorry, could you try again with my mistake corrected.
Here's an excerpt from the cpp man page on my system:
-x c -x c++ -x objective-c -x assembler-with-cpp Specify the source language: C, C++, Objective-C, or assembly. This has nothing to do with standards conformance or extensions; it merely selects which base syntax to expect. If you give none of these options, cpp will deduce the language from the extension of the source file: .c, .cc, .m, or .S. Some other common extensions for C++ and assembly are also recognized. If cpp does not recognize the extension, it will treat the file as C; this is the most generic mode.
I thought this -x c feature was portable, where as relying on cpp to default to C mode for a .h file seems much less so. Perhaps we should just spit out a .c file instead of a .h file. It wouldn't make much difference to c2hs as far as I can see.
Duncan
participants (2)
-
Duncan Coutts
-
Ruben Zilibowitz