1

Following this solution, I use #include "...frontend/tokens.mll" in my lexer.mll, then I use cpp -P frontend/lexer.mll -o frontend/gen/lexer.mll to generate the complete mll file. This solution worked before under Ubuntu.

Now, I try to do this in Mac OS 10.11.1, it gives an error clang: error: no input files.

gcc -v returns

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.29)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

I don't see where I use XCode, or PCH file. Does anyone know how I should configure the environment to make cpp work?

Edit 1:

cpp --version returns

Apple LLVM version 7.3.0 (clang-703.0.29)
Target: x86_64-apple-darwin15.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

And an example from the comment:

enter image description here

Community
  • 1
  • 1
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
  • Please run `cpp --version`, and also show the output of running `cpp` with the `-v` flag to show verbose output. Please also show the contents of your `.mll` file. – jtbandes Apr 10 '16 at 01:38
  • You've not given us enough information to work on. You need to show the exact command you're running because the `cpp` command you show doesn't generate messages with `clang` as the program name (at least, not obviously when I try it — granted, I'm using `Apple LLVM version 7.3.0 (clang-703.0.29) Target: x86_64-apple-darwin15.4.0` which is a bit newer, but I don't expect it to be a change). You should show some minimal material (one or two lines per file might be enough), and the `makefile` rules you're using, and the output from `make` exactly. – Jonathan Leffler Apr 10 '16 at 01:38
  • Also, what does this have to do with Xcode or PCH files? – jtbandes Apr 10 '16 at 01:39
  • It looks like `cpp` on OS X is equivalent in some way to `clang -E`, and if there's an error it'll say `clang: error: `. But that wouldn't explain your problem. Are you sure you're running the right command, and from the right directory? – Ismail Badawi Apr 10 '16 at 01:41
  • 1
    Are you sure `clang: error: no input files` is the only message you get? – Ivan Aksamentov - Drop Apr 10 '16 at 01:46
  • Given: `echo '#include "zzz"' > xxx; echo 'from zzz' > zzz; cpp -P xxx -o yyy`; then `cat yyy` reveals `from zzz`. Which is one way of showing that with proper setup of the files, the Mac `cpp` command does what's required. – Jonathan Leffler Apr 10 '16 at 01:59
  • Were it not that the bounty prevents this question from being closed, I'd be nominating that it should be closed 'unclear what you are asking' because there isn't enough information to identify (let alone reproduce) your problem, let alone provide a solution to it. – Jonathan Leffler Apr 10 '16 at 02:02
  • Guys, I have updated the OP with the simple example... – SoftTimur Apr 10 '16 at 03:46
  • 'cpp -P xxx -o yyy' you need it to be -> 'echo "blahblahblah.cpp" > xxx' – Dendi Suhubdy Apr 14 '16 at 19:41

4 Answers4

2

So if I understand correctly what you are trying to do, you want to run the c preprocessor on a file to produce text output which will be stored in another file. I don't know why but, here is a command that will accomplish that :

clang -x c frontend/lexer.mll -E -P -o frontend/gen/lexer.mll

This invokes clang; sets the language to C (-x c); gives your file; asks for preprocessing only, no compile or link (-E); no line info in the output (-P), stores it in frontend/gen/lexer.mll

Xcode is an IDE that runs clang. If you are working in ocaml it may not be helpful to use Xcode since it wouldn't know what to do with ocaml files.

1

It could be a bug from clang, as this one works for me:

$ cpp -P xxx yyy
$ cat yyy
from zzz

and

$ clang --version
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
Hang
  • 387
  • 1
  • 6
-1

1 - open XCode

2 - Create a new XCode project

3 - choose tab of OSX

4 - choose Application

5 - choose Command Line tool

6 - in next window you have to enter product name etc

7 - and choose c++ as a language

Max Leske
  • 5,007
  • 6
  • 42
  • 54
scbas
  • 3
  • 4
-1

'cpp -P xxx -o yyy' you need it to be -> 'echo "blahblahblah.cpp" > xxx'

Dendi Suhubdy
  • 2,877
  • 3
  • 19
  • 20