0

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

dahko37
  • 131
  • 4
  • 11
  • 1
    Make sure that when you link, all the files are included. It would appear the appropriate .o (or .obj on Windows) file is not part of the link command. For example, `pin.o` or `pinmockup.o` is missing from the linker command line. – ChrisSc Nov 13 '22 at 18:20

0 Answers0