How to use the FTGL C API from C++?

536 views Asked by At

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
2

There are 2 answers

0
Nicol Bolas On BEST ANSWER

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.

0
IanPudney On

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.