MCUXpresso compiler directives between projects?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MCUXpresso compiler directives between projects?

1,274 次查看
nicholas99
Contributor II

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! 

0 项奖励
回复
2 回复数

1,101 次查看
Carlos_Mendoza
NXP Employee
NXP Employee

Hi Nicholas,

I think you can follow some of the recommendations from this post:

https://community.nxp.com/thread/477953?sr=inbox&ru=292133 


Hope it helps!

Best Regards,
Carlos Mendoza
Technical Support Engineer

0 项奖励
回复

1,102 次查看
nicholas99
Contributor II

Hello,

I had already read through the topic you linked to multiple times before posting my question and it was not helpful because it is not the same situation as what I have described. The  original question starts off similarly but 1) the answer goes in a different direction, and 2) in my instance the function called's source code is in an alternate project. I have unique projects for each hardware device and desired one project that is shared (included) in each hardware. My issue came with command processing, a common communication command to perform XYZ is performed uniquely to the hardware and calls hardware unique functions (if hardware A then Bluetooth, if hardware B then Ethernet for example). When I compile project A I get compiler errors for missing/undefined Ethernet functions, and when compiling project B I get errors for missing/undefined Bluetooth functions (to stick with my examples).

The easy but terrible solution is to include all source code in all projects but this is incredibly undesireable because it would require all hardware modules to store excess firmware meant for every other module.

FYI, I have changed what I was trying to do so I could solve the problem another way. Now I separated the code that processes the commands into multiple files and put each of those into the hardware project they belong to. I had to add functions for each command in the protocol - even when it does not apply to a specific hardware module in order to prevent some compile errors and then just left the functions blank when appropriate. It's not as ideal as what I originally wanted but it will work.

0 项奖励
回复