Not sure if extern
is the correct way to handle this situation, but it is what I've currently attempted.
I have a library sharing common code across multiple projects, some of which have different pin configuration that must be done during the _system_pre_init()
function in the library (which is called prior to main()
due to microprocessor behavior).
Ex:
boot.cpp
extern void Init(void);
// called prior to main() due to microprocessor behavior
extern "C" int _system_pre_init(void)
{
Init();
return 1;
}
board1.hpp
void Init(void);
board1.cpp
void Init(void)
{
// init specific to board 1
}
board2.hpp
void Init(void);
board2.cpp
void Init(void)
{
// init specific to board 2
}
The plan was for the project implementing the libary to #include whatever board header it needed, which would in turn define the appropriate Init() function.
main.cpp
#include "board1.hpp"
int main(int argc, char ** argv)
{
//...
}
However, it doesn't look like the board header I include has any effect over the definition of Init(). How can I manage this? Or is there some other paradigm that fits better here?
At most of my embedded system employment this idea was implemented in the make file. i.e. you either build target1 or you build target2. The decision of which you are building is done by the user by selecting the correct target of the make file.
When building the whole system, you would specify 'all'.
With the target identified, the make file only builds the files required by that target.
Conditional compilation flags were not used.
But, perhaps this is not useful ... if you don't use make.