Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Regular Contributor
bemipefe
Posts: 75
Registered: ‎06-14-2013
My Device: Z10

BlackBerry 10 OS define to create cross-platform application

Hi.

I'm developing a cross-platform library and i need some code to be compiled only on the specific OS, for now Android and BlackBerry.

 

I need the name of a define to put in a #ifdef block to compile some code only when the destination OS is BlackBerry. This to avoid errors when I'm compiling for Android OS.

 

I found the __QNX__ define but this define seem to be not defined at compilation time and the code in the #ifdef block is not taken. Does exist a define to identify the OS environment for BlackBerry ? 

Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: BlackBerry 10 OS define to create cross-platform application

Using "echo | ntoarm7-gcc -dM -E -" produces a list of predefined symbols (found by googling "gcc show predefined symbols").

This list includes __QNX__ and __QNXNTO__ so that one should really be defined for you. Are you certain it's not?

For comparison, you should also see __VERSION__ set to the same value as "ntoarm7-gcc --version" shows ("4.6.3" here), as well as __ARM__ and numerous others.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Regular Contributor
bemipefe
Posts: 75
Registered: ‎06-14-2013
My Device: Z10

Re: BlackBerry 10 OS define to create cross-platform application

I found the __QNX__ define using the same method you have described (running ntoarm7-gcc -dM -E -).

The IDE seem to recognize the __QNX__ symbol but when I compile the project i get the error:

error: 'MyClass' has not been declared In file included from ../src/main.cpp:10:0:

 

This mean that the #ifdef block the class declaration. The error disappear if I comment the #ifdef and #endif declarations.

Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: BlackBerry 10 OS define to create cross-platform application

Just ahead of the suspect #ifdef, try printing the value of that symbol. Use something like #pragma message("__QNX__ is " __QNX__) or #warning "__QNX__ is " __QNX__.

It seems likely to me that the issue isn't that the symbol is undefined but rather something with the logic of the ifdefs and includes.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!