I have to call a C++ wrapper function from C, I am using Atmel Studio 7. I created three files as below in a gcc c/c++ executable project
wrapper.cpp
#include "wrapper.h" using namespace std; extern "C" int checker() { //function definition }
wrapper.h
#ifndef HEADER_FILE #define HEADER_FILE #ifdef __cplusplus extern "C" { #endif //declare functions here int checker(); #ifdef __cplusplus } #endif #endif
main.c
#include <stdio.h> #include "wrapper.h" int main() { printf("%d\n",checker()); return 0; }
When I build this project I get an error as "undefined reference checker". The same set of code works fine on Linux. Not sure what is the issue. I think the compiler is unable to define __cplusplus (just a guess not sure if that is the issue) Please help.