In a C++ project, I'm trying to call this function, which is defined in C:
int CyBtldr_RunAction(CyBtldr_Action action, const char* file, const uint8_t* securityKey,
uint8_t appId, CyBtldr_CommunicationsData* comm, CyBtldr_ProgressUpdate* update);
CyBtldr_ProgressUpdate is also defined in C as:
typedef void CyBtldr_ProgressUpdate(uint8_t arrayId, uint16_t rowNum);
And I'm getting the following undefined reference error. Am I missing something?
.\bootloader.cpp:88: error: undefined reference to 'CyBtldr_RunAction(CyBtldr_Action, char const*, unsigned char const*, unsigned char, CyBtldr_CommunicationsData*, void (*)(unsigned char, unsigned short))'
You need
extern "C"
because c++ function names are changed at compile time. This is what allows function and method overloading in c++.
You can use it to wrap the function declaration like this
extern "C" {
int CyBtldr_RunAction(CyBtldr_Action action, const char* file, const uint8_t* securityKey, uint8_t appId, CyBtldr_CommunicationsData* comm, CyBtldr_ProgressUpdate* update);
}
Or to include the file where it's declared, like
extern "C" {
#include "cybtldr_runaction_header.h";
}
for an extended explanation and more, read this documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With