H
Henrik Goldman
I have an application which compiles on a number of different platforms. Now
I'm trying to incorporate an external library which is only available to a
subset of the platforms that my application support.
This is ok as it will give increased usability on some platforms but not
all.
The problem however is to remove code at compiletime when my application is
compiled on a platform which does not support this library.
Using the preprocessor I can enumerate all the platforms on which this
library support like:
#if (defined(_WIN32) && defined(_M_IX86)) || \
(defined(_WIN64) && defined(_M_AMD64)) || \
(defined(__APPLE__) && defined(__ppc__)) || \
(defined(__APPLE__) && defined(__i386__)) || \
....
#endif
However in those places of my application where the support code to use the
library is defined I'd like to condtionally enable the code on a platform
where support is present.
More specifically I'd like to do:
INCLUDE_MY_LIB_SUPPORT_START
printf("This platform has library support\n");
INCLUDE_MY_LIB_SUPPORT_END
On platforms with library support it the macro would expand to nothing. On
unsupported platforms it would expand to #if 0 and #endif and thus removed
by the compiler.
The first few tests showed however that this is not easily possible. The
alternative is then something like:
#ifdef INCLUDE_MY_LIB_SUPPORT
printf("This platform has library support\n");
#endif
This is not as good however as one can easily forget to include the needed
header file and then you get no warning but code on supported platforms will
still be removed.
Is there a way to solve this? One other thing is to define it at compile
time through a switch like -DMY_LIB_SUPPORT but I'd like to keep down the
number of switches on commandline.
Thanks.
-- Henrik
I'm trying to incorporate an external library which is only available to a
subset of the platforms that my application support.
This is ok as it will give increased usability on some platforms but not
all.
The problem however is to remove code at compiletime when my application is
compiled on a platform which does not support this library.
Using the preprocessor I can enumerate all the platforms on which this
library support like:
#if (defined(_WIN32) && defined(_M_IX86)) || \
(defined(_WIN64) && defined(_M_AMD64)) || \
(defined(__APPLE__) && defined(__ppc__)) || \
(defined(__APPLE__) && defined(__i386__)) || \
....
#endif
However in those places of my application where the support code to use the
library is defined I'd like to condtionally enable the code on a platform
where support is present.
More specifically I'd like to do:
INCLUDE_MY_LIB_SUPPORT_START
printf("This platform has library support\n");
INCLUDE_MY_LIB_SUPPORT_END
On platforms with library support it the macro would expand to nothing. On
unsupported platforms it would expand to #if 0 and #endif and thus removed
by the compiler.
The first few tests showed however that this is not easily possible. The
alternative is then something like:
#ifdef INCLUDE_MY_LIB_SUPPORT
printf("This platform has library support\n");
#endif
This is not as good however as one can easily forget to include the needed
header file and then you get no warning but code on supported platforms will
still be removed.
Is there a way to solve this? One other thing is to define it at compile
time through a switch like -DMY_LIB_SUPPORT but I'd like to keep down the
number of switches on commandline.
Thanks.
-- Henrik