I developed a library for an stm32 microprocessor. Now, I am creating a mockup of the peripherals so I can test the higher layers without having to actually use the hardware. I am new to this kind of development so I don't know what is the best approach. This is what I did:
In my hpp I have two definitions of a class, like this:
#ifndef MOCKUP
class Pin:
// Pin definition.
#endif
#ifdef MOCKUP
class Pin:
// Pin Mockup definition.
#endif
Then I have two cpp, pin.cpp and pinmockup.cpp, like this:
#ifndef MOCKUP
#include <pin.hpp>
// pin implementation
and the mockup:
#ifdef MOCKUP
#include <pin.hpp>
// pin mockup implementation
Last, in visual studio I create an external project called Pin_TestCase. Then I add necessary paths to additional includes in project settings, and I add MOCKUP in preprocessor definitions. The IDE detects the libraries correctly, but when I use the corresponding functions, the next error shows:
Code:
#include "ST-LIB.hpp"
#include <iostream>
int main()
{
Pin::register_pin(PA10, NOT_USED);
std::cout << "Hello World!\n";
}
Errors:
LNK2019 unresolved external symbol "public: static void __cdecl Pin::register_pin(class Pin &,enum Operation_Mode)" (?register_pin@Pin@@SAXAEAV1@W4Operation_Mode@@@Z) referenced in function main StateMachine_TestCase
Error LNK2001 unresolved external symbol "class Pin PA10" (?PA10@@3VPin@@A) StateMachine_TestCase