0
votes

There are two head files _stub_defs.h

///stub code
#pragma once
#include "random.h"
#include <stdarg.h>

and stasrg.h

#ifndef __GNUC_VA_LIST
#define __GNUC_VA_LIST
typedef __builtin_va_list __gnuc_va_list;
#endif

When I use my cross-compiler(sparc-rtems-gcc) to compile, the two head files both are included.Then the terminal tells me:

warning: #pragma once is obsolete
stdarg.h: conflicting types for `__gnuc_va_list'

stdarg.h: previous declaration of `__gnuc_va_list'

Obviously, #include guards does not work.Is this the problem of head files' codes or the problem of my cross-compiler?

1
Is _stub_defs.h a toolchain header or could you modify it? If you can use there the same approach of stasrg.h. - LPs
Of course the include guards work. The symbol must be defined somewhere else already. - Paul Ogilvie
Where did you get stasrg.h from? (It isn't a standard header that I've come across — it is a typo for <stdarg.h>?) If you wrote it, you have no business doing that. That said, if you're compiling in C11 mode and the typedefs are the same, you shouldn't get that error. And you should get rid of #pragma once — header guards work as long as they're not misused. - Jonathan Leffler

1 Answers

1
votes

The include guards work. You have another problem.

The best way to debug this is to run only the C preprocessor. For gcc (including cross compiler gcc), you can use the -E option. Just add this to your compile stage. Instead of getting an object file, you will get a C file after the preprocessor stage.

Take that file, and search for the duplicate definition there. The file will also have markers that tell the compiler which file this definition originally came from, as well as markers when includes are nested. If you follow those, you will see both where the two definitions come from and which file included each of them.