Create a build environment for “C” project to dynamically select folders during compile time

点点圈 提交于 2019-12-12 04:40:40

问题


Lets say my folder structure is something like this ..

+-- Application
|
+-- MICRO_CONTROLLER_1
|
+-- MICRO_CONTROLLER_2
|
+-- MICRO_CONTROLLER_3

and i have a compile switch ( SELECT_MICRO) set to #define SELECT_MICRO == MICRO_CONTROLLER_1 , then my project should build application with driver files in MICRO_CONTROLLER_1 , similarly if #define SELECT_MICRO == MICRO_CONTROLLER_2 , then application should build application with driver files in MICRO_CONTROLLER_2

Please let me know if there template to achieve the above.


回答1:


You can export that particular path of the folder you want to build and supply the path to the executable. You can get further info. in this thread.

How I could add dir to $PATH in Makefile?

Or simply maintain different Makefiles to make different builds and use make -f to run that particular makefile.

I hope this is what you finally want to perform.




回答2:


Typically you would define your pre-processor definitions to tell the pre-processor to include only, for instance, MICRO_CONTROLLER_1 blocks of code and ignore everything else.

Something like the following should suffice:

#if defined(MICRO_CONTROLLER_1)
// Block of code that is only available to MICRO_CONTROLLER_1
#elif defined(MICRO_CONTROLLER_2)
// ...
// All other microcontrollers you are supporting would follow this structure.
#endif

Then you would need to define MICRO_CONTROLLER_1. If you're using an IDE for development, there is typically a project option for pre-processor directives. This is where you would define MICRO_CONTROLLER_1. You could then create different "configurations" - one for each of the microcontrollers you are targeting.




回答3:


This can only work if the directories have only include files. #define is a preprocessor directive. If the directories have source files, you need to solve it at the build system layer, not the preprocessor layer.

Assuming it's just include files, you'd just #include SELECT_MICRO # "Interface.h"



来源:https://stackoverflow.com/questions/21281949/create-a-build-environment-for-c-project-to-dynamically-select-folders-during

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!