Deepak
Deepak

Reputation: 1545

clang not compiling c programs?

I use clang to compile most of the times when programming in c. Suddenly it has stopped working. Whenever I try to compile something it gives me this output Suppose the file name is test.c

clang test.c 

In file included from test.c:1:
/usr/include/stdio.h:33:11: fatal error: 'stddef.h' file not found
# include <stddef.h>
          ^
1 error generated.

the source of test.c is :

#include <stdio.h>
#include <stdlib.h>

int main( int argc, char *argv[] )
{
  printf("\nthis is a sample c program\n");
  return EXIT_SUCCESS;
}

Note: on other compilers like gcc it still works. What should I do to get clang working back?

In case you need any info about system: I am using Ubuntu 13.10 32-bit. Text editor : Emacs.

I also tried to un-installing clang and then reinstalling still get the same errors.


I found the file in "usr/include/linux" and then pasted it into "usr/include" it doest show me error for same file now but asks for another one

In file included from test.c:1:
In file included from /usr/include/stdio.h:74:
/usr/include/libio.h:50:10: fatal error: 'stdarg.h' file not found
#include <stdarg.h>
     ^
1 error generated.

Now I tried to search for the new file "" and found more than 1 file with same name in different folder which makes it confusing which is the right one I need to copy paste in the directory clang wants.

Is there any other way by which I can fix the issue with header files?


Now i have found the config.h file for clang. The two variables responsible for include files are as follows in the file with their current values:

/* Relative directory for resource files */
#define CLANG_RESOURCE_DIR ""

/* Directories clang will search for headers */
#define C_INCLUDE_DIRS "/usr/include/i386-linux-gnu:/usr/include/i686-linux-gnu:/usr/include"

but I have no clue what value i should replace to get it working. Is these any way I can completely reconfigure clang?

Upvotes: 6

Views: 10280

Answers (4)

user3230547
user3230547

Reputation: 56

According to this: http://clang.llvm.org/docs/LibTooling.html#libtooling-builtin-includes

CLang provides it as a built-in include. It says that it is provided by CLang and must be in the path $(dirname /path/to/tool)/../lib/clang/3.3/include, but I found that this is only true in Linux. In Windows, the path is $(dirname /path/to/tool)/../bin/clang/3.3/include, or in other words, the clang directory that contains the includes must be under the bin directory. This has now changed in version 3.7. Now the path to the includes from the clang executable is ../lib/clang...

I am pretty sure that the entire clang/lib/clang directory must be at the location where CLang is looking for it.

You can see where clang is looking by using the -v switch.

Upvotes: 1

Deepak
Deepak

Reputation: 1545

After spending some time I found that clang was not working due to missing header files in "/usr/include/" directory. Many other Linux users are also facing same problems. In my case this happened due to updating to new release of Ubuntu.

I removed clang by:

sudo apt-get remove clang

And then installed clang-3.3 which is different version of clang

sudo apt-get install clang-3.3

Now clang is working fine for me.

Upvotes: 7

Justin Jasmann
Justin Jasmann

Reputation: 2353

From here: http://clang.llvm.org/doxygen/config_8h_source.html

See if you can find config.h for Clang. It looks to be generated by the configure process.

There are two variables listed in there that could be responsible for this.

00010 /* Relative directory for resource files */
00011 #define CLANG_RESOURCE_DIR ""
00012 
00013 /* Directories clang will search for headers */
00014 #define C_INCLUDE_DIRS ""

You may either need to change those variables to reflect the proper location, or re-configure clang.

Upvotes: 1

Bill Lynch
Bill Lynch

Reputation: 81986

This is a known bug in Ubuntu. You can track this at the Ubuntu and Debian bugtrackers:

It appears that a temporary workaround is to install the clang-3.3 package instead.

Upvotes: 3

Related Questions