Menu

#1286 C file including stdbool fail parsing

None
closed
parsing (146)
5
2022-01-25
2012-11-29
maxime-esa
No

If a C file contains this statement:
#include <stdbool.h>

(which is present in the standard C/C++ directories)

It is not found by SWIG:

swig -includeall -outdir . -python ./DV.i
asn1crt.h:5: Error: Unable to find 'stdbool.h'

The workaround I found was to use the -ignoremissing flag, but there might be an issue in the parser with the include directories.

Discussion

  • Olly Betts

    Olly Betts - 2022-01-25
    • status: open --> closed
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2022-01-25

    As the manual says about -includeall:

    By default, the #include is ignored unless you run SWIG with the
    -includeall option. The reason for ignoring traditional includes
    is that you often don't want SWIG to try and wrap everything included
    in standard header system headers and auxiliary files.

    I'm sure you don't actually want SWIG to try to wrap everything in <stdbool.h>, but to get it to do this unwanted thing you would need to tell SWIG where to find it with -I - it's a compiler-specific header and so stored in a compiler-specific directory, and SWIG has no way of knowing what compiler you're using.

    E.g. I have the following stdbool.h headers on this machine for various different compilers and for C vs C++:

    /usr/include/c++/10/tr1/stdbool.h
    /usr/include/c++/11/tr1/stdbool.h
    /usr/include/c++/4.7/tr1/stdbool.h
    /usr/include/c++/4.8/tr1/stdbool.h
    /usr/include/c++/8/tr1/stdbool.h
    /usr/include/c++/9/tr1/stdbool.h
    /usr/lib/gcc/i686-w64-mingw32/10-posix/include/stdbool.h
    /usr/lib/gcc/i686-w64-mingw32/10-posix/include/c++/tr1/stdbool.h
    /usr/lib/gcc/i686-w64-mingw32/10-win32/include/stdbool.h
    /usr/lib/gcc/i686-w64-mingw32/10-win32/include/c++/tr1/stdbool.h
    /usr/lib/gcc/x86_64-linux-gnu/10/include/stdbool.h
    /usr/lib/gcc/x86_64-linux-gnu/11/include/stdbool.h
    /usr/lib/gcc/x86_64-linux-gnu/4.7/include/stdbool.h
    /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdbool.h
    /usr/lib/gcc/x86_64-linux-gnu/8/include/stdbool.h
    /usr/lib/gcc/x86_64-linux-gnu/9/include/stdbool.h
    /usr/lib/gcc/x86_64-w64-mingw32/10-posix/include/stdbool.h
    /usr/lib/gcc/x86_64-w64-mingw32/10-posix/include/c++/tr1/stdbool.h
    /usr/lib/gcc/x86_64-w64-mingw32/10-win32/include/stdbool.h
    /usr/lib/gcc/x86_64-w64-mingw32/10-win32/include/c++/tr1/stdbool.h
    /usr/lib/gcc-snapshot/include/c++/12/tr1/stdbool.h
    /usr/lib/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12/accel/amdgcn-amdhsa/include/stdbool.h
    /usr/lib/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12/accel/nvptx-none/include/stdbool.h
    /usr/lib/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12/include/stdbool.h
    /usr/lib/llvm-10/lib/clang/10.0.1/include/stdbool.h
    /usr/lib/llvm-11/lib/clang/11.1.0/include/stdbool.h
    /usr/lib/llvm-13/lib/clang/13.0.1/include/stdbool.h
    /usr/lib/llvm-6.0/lib/clang/6.0.1/include/stdbool.h
    /usr/lib/llvm-7/lib/clang/7.0.1/include/stdbool.h
    /usr/lib/llvm-8/include/c++/v1/stdbool.h
    /usr/lib/llvm-8/lib/clang/8.0.1/include/stdbool.h
    

    -includeall is rarely useful unfortunately. It's handy to be able to follow includes between headers for the library being wrapped, but if any of those headers include a system header then -includeall doesn't know to stop including all and is unlikely to give a useful result.

     

Log in to post a comment.