va_list has not been declared

前端 未结 2 1436
终归单人心
终归单人心 2021-01-07 22:51

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


        
相关标签:
2条回答
  • 2021-01-07 23:21

    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;
    
    }
    
    0 讨论(0)
  • 2021-01-07 23:28

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

    #include <stdarg.h>
    

    or

    #include <cstdarg>
    
    0 讨论(0)
提交回复
热议问题