Skip to content

Getting Multiple Definition error when including a utils file in multiple components #2634

Answered by LeStarch
epdalessandro asked this question in Q&A
Discussion options

You must be logged in to vote

Here is a quick refactor that will help:

utils.hpp: has definitions of class Lock and function prototypes.

#include <vector>
#include <Os/Mutex.hpp>
#ifndef UTILS
#define UTILS

class Lock {
    public:
        Lock(Os::Mutex _mutex) : mutex(_mutex) { mutex.lock(); }
        ~Lock() { mutex.unlock(); }
    private:
        Os::Mutex mutex;
};

uint64_t bytesToUint(const char* bytes, uint16_t len);

std::vector<uint64_t> getDataFromFields(const char* data, std::vector<uint16_t> &sizes);
void ProcessData(uint32_t messageSize, std::vector<char> receivedBytes, std::vector<uint16_t> &fieldSizes, void (*SubsystemDataProcessor) (uint8_t msgType));

#endif

utils.cpp: has implementation of functions.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@epdalessandro
Comment options

@epdalessandro
Comment options

Answer selected by epdalessandro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants