AnsweredAssumed Answered

MCUXpresso compiler directives between projects?

Question asked by nicholas99 on Sep 18, 2018
Latest reply on Oct 30, 2018 by nicholas99

I want to use something like a compiler directive so that a portion of code is compiled based on which other project it is being compiled with or run with. Such as:

#if defined _PROJECT_A

//code for project A that uses external FunctionA() from project A

#elseif _PROJECT_B

//code for project B that uses external FunctionB() from project B

#endif

I have 3 projects for 2 hardware modules where one project contains code that is used by both hardware modules:

Project-A                  (Hardware A)

Project-B                  (Hardware B)

Project-Common      (Shared Communication Protocol)

 

The first two projects (A & B) are very unique and different. But they share the same communication protocol, let's say for example a custom layer for interpreting data over USB. Later I will have additional unique hardware projects so I don't want to write the communication code into each project separately and have to update or bug fix the same code in multiple files, so I created a separate project just for the communication protocol and just #include it in Project-A and Project-B. It works great until I needed to use project specific external functions from A and B. Now I am getting errors that FunctionA() is not defined when I try to compile Project-B and vice versa - which makes sense.

 

95% of the code in the Project-Common is the same for all modules, but now I need to write some limited special code for each Project-A and Project-B something like if communication data == xyz then (if ProjectA run FunctionA) (if ProjectB run FunctionB) where FunctionA and Function B are each public functions in their similarly named project.

 

To get rid of errors I could probably just #include all of the projects together but I don't want the code from every module to be compiled into the code of every other project! 

Outcomes