Search code examples
c++macosocamllex

"Clang: error: no input files" in OS X


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


Solution

  • 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.