-1

I'm trying to use C Redis client library in the Cinder framework. I'm not sure where to put the extern "C" declarations or if it works even if I put it correctly. Please help.

dazzphot
  • 307
  • 1
  • 3
  • 11
  • 1
    http://stackoverflow.com/questions/1041866/in-c-source-what-is-the-effect-of-extern-c/1041880#1041880 – Steephen Apr 08 '15 at 00:40
  • I'm aware of extern "C". But I used it in the same file where I define the template methods of the framework and it didn't work. I was wondering if I put it in the wrong place. Must it go at the beginning of compilation or something? – dazzphot Apr 08 '15 at 00:46

2 Answers2

2

First of all, keep your C++ code in .cpp or .cc files so that it compiles as C++ code and keep your C code in .c files so that they will compile as C code.

Next, in the .h files that reference the code in the .c files, add this:

#ifdef __cplusplus
extern "C" {
#endif

   void sharedFunction();

#ifdef __cplusplus
}
#endif

Basically all you are doing is saying.. if C++ is using these functions, find them in the C code. If C is using these functions, use them normally.

Hashtag
  • 75
  • 4
-2

extern "C" is added in the global scope.

  • Can it be anywhere or does it have to be at the beginning? Since I'm doing it in a framework, I couldn't find the starting point of compilation. And I'm using the dynamic library functions in a class method. So I don't know exactly where to put it. – dazzphot Apr 08 '15 at 00:49
  • Always puts before using the function of the imported library, in your .cpp file. – please delete me Apr 08 '15 at 02:52