S
stephen.diverdi
This isn't strictly a language issue, but it seems enough of a cross-
IDE and -platform concern to merit asking here.
I'm running into a maintenance issue for a library I've written. The
problem is I have a config.h file that includes a bunch of #define
directives that control the compilation of the library. Those
directives can also be overridden by options to the compiler. The
problem arises when I compile the library with one set of directives,
and then in a project that links to the library, compiler options
override the library's directives and the headers that are included
don't match the library that was compiled. Strange errors and fun
debugging ensues.
I'd like to find a way to test for this condition automatically,
ideally at compile time without runtime overhead. One option is to
provide something like:
config.h:
#define FLAG_SSE 0x01
#define FLAG_OPENGL 0x02
#define FLAG_WIN32 0x04
bool checkCompilationFlags ( int flags );
config.cpp:
static int COMPILATION_FLAGS = FLAG_SSE | FLAG_OPENGL | FLAG_WIN32;
bool checkCompilationFlags ( int flags ) { return ( flags ==
COMPILATION_FLAGS ); }
Therefore, when the library is compiled, COMPILATION_FLAGS will store
the configuration that was used, and the application can call
checkCompilationFlags with its understood values for the flags and see
if they match. This isn't great though, as it requires calling the
function somewhere in the application, it adds some (small) runtime
overhead, and it only raises the error at runtime. A perfect solution
would not require anything more than including the headers in the
application, would compile away with optimization, and would raise a
compile-time error in the event of a mismatch.
Has anyone dealt with this issue before? Are there any standard
approaches or clever tricks? Any ideas? Thanks,
-stephen diverdi
(e-mail address removed)
IDE and -platform concern to merit asking here.
I'm running into a maintenance issue for a library I've written. The
problem is I have a config.h file that includes a bunch of #define
directives that control the compilation of the library. Those
directives can also be overridden by options to the compiler. The
problem arises when I compile the library with one set of directives,
and then in a project that links to the library, compiler options
override the library's directives and the headers that are included
don't match the library that was compiled. Strange errors and fun
debugging ensues.
I'd like to find a way to test for this condition automatically,
ideally at compile time without runtime overhead. One option is to
provide something like:
config.h:
#define FLAG_SSE 0x01
#define FLAG_OPENGL 0x02
#define FLAG_WIN32 0x04
bool checkCompilationFlags ( int flags );
config.cpp:
static int COMPILATION_FLAGS = FLAG_SSE | FLAG_OPENGL | FLAG_WIN32;
bool checkCompilationFlags ( int flags ) { return ( flags ==
COMPILATION_FLAGS ); }
Therefore, when the library is compiled, COMPILATION_FLAGS will store
the configuration that was used, and the application can call
checkCompilationFlags with its understood values for the flags and see
if they match. This isn't great though, as it requires calling the
function somewhere in the application, it adds some (small) runtime
overhead, and it only raises the error at runtime. A perfect solution
would not require anything more than including the headers in the
application, would compile away with optimization, and would raise a
compile-time error in the event of a mismatch.
Has anyone dealt with this issue before? Are there any standard
approaches or clever tricks? Any ideas? Thanks,
-stephen diverdi
(e-mail address removed)