This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Include various C files

I would like to do conditional compiling and include different C files based on the hardware being used. For example:

#ifdef HARDWARE_MODULE_1

#include "hardware_module_1.c"

#endif

#ifdef HARDWARE_MODULE_2

#include "hardware_module_2.c"

#endif

...

Everything works fine this way only debugging becomes a problem. Breakpoints don't work correctly when placed in the C file that's included that way. The program ends up breaking somewhere else random in the code (different C file altogether) When I manually add file to the project everything seems to be working fine. I'm using uVision V4.60.6.10

Parents
  • Multiple targets is most probably the best route.

    A different route is to instead have the C files look like:

    hardware_module_1.h:

    #ifdef HARDWARE_MODULE_1
    
    void hardware_module1_stuff(void);
    
    #endif
    

    hardware_module_1.c:

    #include "config.h"
    
    #ifdef HARDWARE_MODULE_1
    
    #include "harware_module_1.h"
    
    void hardware_module1_stuff(void) {
        ...
    }
    
    #endif // HARDWARE_MODULE_1
    

    main.c:

    #include #config.h"
    
    #ifdef HARDWARE_MODULE_1
    #include "hardware_module_1.h"
    #endif
    
    #ifdef HARDWARE_MODULE_2
    #include "hardware_module_2.h"
    #endif
    
    ...
    #ifdef HARDWARE_MODULE_1
        hardware_module1_stuff();
    #endif
    
    #ifdef HARDWARE_MODULE_2
        hardware_module2_stuff();
    #endif
    

Reply
  • Multiple targets is most probably the best route.

    A different route is to instead have the C files look like:

    hardware_module_1.h:

    #ifdef HARDWARE_MODULE_1
    
    void hardware_module1_stuff(void);
    
    #endif
    

    hardware_module_1.c:

    #include "config.h"
    
    #ifdef HARDWARE_MODULE_1
    
    #include "harware_module_1.h"
    
    void hardware_module1_stuff(void) {
        ...
    }
    
    #endif // HARDWARE_MODULE_1
    

    main.c:

    #include #config.h"
    
    #ifdef HARDWARE_MODULE_1
    #include "hardware_module_1.h"
    #endif
    
    #ifdef HARDWARE_MODULE_2
    #include "hardware_module_2.h"
    #endif
    
    ...
    #ifdef HARDWARE_MODULE_1
        hardware_module1_stuff();
    #endif
    
    #ifdef HARDWARE_MODULE_2
        hardware_module2_stuff();
    #endif
    

Children
No data