How to stop Clang from duplicating functions in standard C header files?

I have wonderful C99 codes that are compiled from multiple .c files, and when I compile Clang 2.7, I get very strange errors:

/usr/include/bits/stdio.h:77: multiple definition of `putchar' a2test.o:/usr/include/bits/stdio.h:77: first defined here 

What happens is that the GNU libc header for <stdio.h> declares certain functions, including putchar , like extern __inline__ , and for some reason clang puts the definitions in .o files. Then, when the linker sees duplicate definitions, it fades.

I suspect a configuration problem: when I use clang 2.7, which comes with Debian lenny, everything compiles. But for the class I'm teaching, the software should run on Red Hat Enterprise Linux 5, and my sysadmin created clang 2.7 from the source code. (We don’t use 2.9 because we couldn’t get him to compile hello world, and we don’t use a later version because we couldn’t compile the latest version.)

I am looking for a workaround that will allow me to compile. Either a command line option, or a way to reconfigure clang so that it doesn't do it badly.

I already tried -U__USE_EXTERN_INLINES without effect.

+8
glibc clang
source share
2 answers

LLVM error 5960 shows that this problem occurs due to the interaction between clang C99 support and the old version of GNU libc installed on RHEL 5. It seems that for those of us stuck with RHEL 5, we cannot use clang -std=c99 -Ox for any x > 0 .

+6
source share

Try -std = gnu89; not quite perfect, but should be good enough as a workaround.

+4
source share

All Articles