Search code examples
pycparser

Not able to run basic example of pycparser


I am trying to start with pycparser and was trying to run the examples given on the github repo. I only changed the path of the file to be parsed after saving the sample c file locally. I get the following error and am not sure if there is some pre-processing step that I am missing?

File "D:\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 714, in runfile
execfile(filename, namespace)
  File "D:\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 89, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
  File "C:/Users/Z003RTRP/Desktop/cparse.py", line 20, in <module>
ast = parse_file(filename, use_cpp=True, cpp_path='gcc', cpp_args=r'-Iutils/fake_libc_include')
  File "D:\Anaconda3\lib\site-packages\pycparser\__init__.py", line 86, in parse_file
text = preprocess_file(filename, cpp_path, cpp_args)
  File "D:\Anaconda3\lib\site-packages\pycparser\__init__.py", line 49, in preprocess_file
('Original error: %s' % e))
RuntimeError: Unable to invoke 'cpp'.  Make sure its path was passed correctly
Original error: [WinError 2] The system cannot find the file specified

Solution

  • Take a look at this section of the README - you have to point cpp_path to the C preprocessor on your system. For Windows, it recommends downloading a binary build of Clang and using clang -E