How to tell the preprocessor where it can find its header files ?

Hello,

I am using llvm/clang solution file generated by visual studio. When I say – “Clang-test” – > Set as Start-up Project → build. I generates a bunch of errors saying it cant find
the include files stdio.h, stdlib.h, limits.h. Now how can I tell the preprocessor where it can find its header files. Do I have to add some commands to the visual studio or Do I have to change the helper class “InitHeaderSearch” inside the InitHeaderSearch.cpp of the clangFrontend target. If I have to modify the code then can an expert guide me through the modifications that have to be made.

Thanks.

kalyan ponnala wrote:

Hello,

I am using llvm/clang solution file generated by visual studio. When I
say -- "Clang-test" -- > Set as Start-up Project -> build. I generates
a bunch of errors saying it cant find
the include files stdio.h, stdlib.h, limits.h. Now how can I tell the
preprocessor where it can find its header files. Do I have to add some
commands to the visual studio or Do I have to change the helper class
"InitHeaderSearch" inside the InitHeaderSearch.cpp of the clangFrontend
target. If I have to modify the code then can an expert guide me through
the modifications that have to be made.

Same as with any compiler, even MSVC: you pass a -I switch. (When you
set the include paths in the project properties, internally, the VS IDE
passes -I switches to the compiler proper.)

Put it on clang's command line like so:

clang "-I\Path\to\Visual\Studio\Dir\VC\Include" <other switches>

Replace \Path\to\Visual\Studio\Dir with the actual path to the Visual
Studio directory.

Chip

You need to modify the VS project file. If you’d created the project using CMake this shouldn’t have been a problem, but in any case…

It sounds like you may have, for whatever reason, told Visual Studio not to use the standard includes (MSVC, the Microsoft Visual C++ compiler that VS invokes internally, of course has a set of standard C/C++ libraries and headers that it will use unless told not to).

Open the Project Properties

Under C/C++, find the Preprocessor page (I’m working from memory here; it varies between versions but should be a page or tab or similar).

In the Preprocessor page, there will be an entry for something like “Use standard Includes” {TRUE|FALSE}. Make sure this is set to TRUE.

You will also find an entry like “[Additional] Include Directories” or similar, which will have a browse button. This is where you specify the folders within the LLVM directory structure that contain header files.

Add here all of the …\include directories for LLVM/Clang (there’s one right inside the llvm directory, and there should be at least one more inside the Clang directory).

Alternatively, you can invoke the compiler on the command line. The options to do so in the MSVC are very much like those for GCC/Clang except I think it uses / rather than – to indicate a command line switch. The properties pages automatically generate these switches for you; for example /Iinclude /Itools\clang\include .

In any case, using CMake is probably far easier. Not only do you not have to mess with such things as include directories, it will automatically set up the build order and other such useful tricks. In fact, some of the clang/LLVM code is generated automatically, and it may be impossible to compile LLVM/clang without running the scripts that generate it (which CMake does automatically, after automatically determining what code needs to be generated).

InitHeaderSearch.cpp is part of clang itself, making changes there will have no effect until you successfully compile clang. I take it you’ve never compiled a compiler before?

Chris