I'm trying to call C code from C++. I have 3 files: pubsub.cpp, pubsublib.c & pubsublib.h. I know I have to use extern "C" in order to call a C function from C++. I've literally tried everything, but I am still getting the following LNK2019 unresolved external symbol error:
LNK2019 unresolved external symbol _thisIsATestFunction referenced in function _main
pubsublib.c
#include "pubsublib.h"
void thisIsATestFunction()
{
// do something
}
pubsublib.h
#ifndef pubsublib_H
#define pubsublib_H
void thisIsATestFunction();
#endif
pubsub.cpp
#include <string>
#include <iostream>
#ifdef __cplusplus
extern "C"{
#endif
#include "pubsublib.h"
#ifdef __cplusplus
}
#endif
using namespace std;
int main() {
thisIsATestFunction();
return 0;
}
I have also tried to just include the functions but I'm getting the same error. I'm really lost at the moment and have searched a lot... Any help would be greatly appreciated.