1. TheMiningBoyAlpha

    OP TheMiningBoyAlpha Advanced Member
    Newcomer

    Joined:
    Apr 24, 2018
    Messages:
    65
    Country:
    United States
    I am trying to use TinyXML2 with my homebrew (for loading level data), and i keep getting errors with a few includes with TinyXML2.

    In file included from C:/Users/TheMiningBoy/Documents/Roblox_DS/Game/source/main.c:12: C:/Users/TheMiningBoy/Documents/Roblox_DS/Game/include/tinyxml2.h:37:13: fatal error: cctype: No such file or directory 37 | # include <cctype> | ^~~~~~~~ compilation terminated. make[1]: *** [/opt/devkitpro/devkitARM/base_rules:85: main.o] Error 1 make: *** [Makefile:170: build] Error 2 Press any key to continue . . .

    Can I have some help getting this to work?​
     
  2. Pk11

    Pk11 A catgirl with a DSi
    Member

    Joined:
    Jun 26, 2019
    Messages:
    262
    Country:
    United States
    You're trying to include a C++ header from a C file. You should be able to either rename "main.c" to "main.cpp" if you're fine with changing to C++ or change "#include <cctype>" to "#include <ctype.h>". In C++ "<c[name]>" and "<[name].h>" headers are the same thing afaik, the "c[name]" style is more C++ style while "[name].h" is more C style, but in plain C you need the "[name].h" include.

    Edit: Note: Changing the include may fix the problem of that include, but since it's trying to include a C++ header it's likely that that's C++ code you're trying to include which won't work if main() is in a C file, so you're probably better off changing main to a cpp file if you're trying to include other C++ code. It shouldn't require much if any code changes.
     
    Last edited by Pk11, Mar 7, 2021
    alexander1970 and banjo2 like this.
  3. TheMiningBoyAlpha

    OP TheMiningBoyAlpha Advanced Member
    Newcomer

    Joined:
    Apr 24, 2018
    Messages:
    65
    Country:
    United States
    thanks, that fixed it, but now i need to find out how to load the xml files
     
    alexander1970 and banjo2 like this.
  4. Coto

    Coto -
    Member

    Joined:
    Jun 4, 2010
    Messages:
    2,746
    Country:
    Chile
    It's possible to add C++ headers in C files (in fact, C and C++ compilers must link objects generated from either one, and are ensured to work):

    headerFile.h
    Code:
    #ifndef __headerFile_h
    #define __headerFile_h
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    extern void func1(); //C++ linkage of C source files
    
    #ifdef __cplusplus
    extern class someClassName; //C++ linkage of C++ classes.
    #endif
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif //__headerFile_h end
    
    Which means:
    Even if this header is added inside a .c file (C source file),
    first declaration will link objects from C into C++ (and viceversa -- very important to understand this), while also stripping out the next class declaration, being C++ only.

    If you add this header into a .cpp file (C++ source file), both rules will apply and will link correctly.
     
    Last edited by Coto, Mar 8, 2021
    Robz8, banjo2 and alexander1970 like this.
  5. TheMiningBoyAlpha

    OP TheMiningBoyAlpha Advanced Member
    Newcomer

    Joined:
    Apr 24, 2018
    Messages:
    65
    Country:
    United States
    i already fixed it
     
Draft saved Draft deleted
Loading...

Hide similar threads Similar threads with keywords - cctype, error,