0

How do I use FTGL's C API from C++ code in Visual Studio 2010?

FTGL uses #ifdef __cplusplus checks to export C and C++ APIs from the same header files.

I tried this:

#ifdef __cplusplus
  #undef __cplusplus
  #include <FTGL/ftgl.h>
  #define __cplusplus
#else
  #include <FTGL/ftgl.h>
#endif

But VS2010 isn't having it:

warning C4117: macro name '__cplusplus' is reserved, '#undef' ignored
warning C4117: macro name '__cplusplus' is reserved, '#define' ignored
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Why are you trying to do that? Since FTGL's header will detect `__cplusplus` itself, why do you need to lie to it by saying you're looking at the header from C code? Let the header do it's job. – Nicol Bolas Aug 05 '13 at 17:55
  • Because I want to use the *C* API in C++ code. – genpfault Aug 05 '13 at 18:00

2 Answers2

2

The macro __cplusplus is a reserved macro, and should be defined automatically by your compiler if you're compiling as C++ code (and not defined otherwise). You shouldn't have to #define it manually, and that's why your compiler throws an error.

IanPudney
  • 5,941
  • 1
  • 24
  • 39
1

How do I use FTGL's C API from C++ code in Visual Studio 2010?

You don't.

The makers of FTGL apparently don't want C++ users to use the C API. So they don't let them.

The __cplusplus macro is a part of the C++ language; it cannot be undefined. Or defined. Or redefined. And since that's what FTGL keys off of, there's no way to trick it into compliance.

The only way to avoid this is to edit FTGL itself.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982