BrownBot Logo BrownBot Head

Calling C++ Defined Functions from C source

10:53 pm Filed under: Uncategorized

Came across this one today, I’m sure I’ve hit it before but of course I didn’t remember. The worst part of the problem is that the error message is not very descriptive (Unresolved external refrence) but the solution is nice and easy.

------------------
foo.h:
------------------
#ifdef __cplusplus
extern "C" {
#endif 

int foo( int ); 

#ifdef __cplusplus
}
#endif 

------------------
foo.cpp
------------------
#include "foo.h" 

int foo( int i ) { ... } 

------------------
main.c
------------------
#include "foo.h" 

int main() { foo(1); }

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.

Powered by WordPress