va_list has not been declared

2019-02-16 08:15发布

问题:

When compiling some working code on Fedora 11, I am getting this error:

/usr/include/c++/4.4.1/cstdarg:56: error: ‘::va_list’ has not been declared

I am using:

[doriad@davedesktop VTK]$ g++ --version
g++ (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2)

Does anyone know what the problem could be?

回答1:

I had the same error message and I solved including one of the next files

#include <stdarg.h>

or

#include <cstdarg>


回答2:

Bringing in the varadic macro set in g++ 4.4 has confusing and twisted semantics. You might get a better idea of what isn't happening by using g++ -E broken_code.cpp and looking at what the pre-processor is bringing in. There are a few dozen GNU C preprocessor directives that could prevent the ::va_list declaration from compiling as __gnuc_va_list which itself is of type __builtin_va_list

The junk code:

$cat junk.cpp
#include <cstdarg>

void foo(char *f, ...) { va_list va; va_start(va, va); }
int main(void) { foo("", "", ""); return 0; }
$ g++ junk.cpp
$ g++ --version
g++ (Ubuntu 4.4.1-4ubuntu9) 4.4.1

compiles and links (with warnings) with the relevant output of g++ -E junk.cpp being:

# 40 "/usr/lib/gcc/i486-linux-gnu/4.4.1/include/stdarg.h" 3 4
typedef __builtin_va_list __gnuc_va_list;
# 102 "/usr/lib/gcc/i486-linux-gnu/4.4.1/include/stdarg.h" 3 4
typedef __gnuc_va_list va_list;
# 45 "/usr/include/c++/4.4/cstdarg" 2 3
# 54 "/usr/include/c++/4.4/cstdarg" 3
namespace std __attribute__ ((__visibility__ ("default"))) {

  using ::va_list;

}