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
Developer
canurabus
Posts: 23
Registered: ‎05-29-2012
My Device: PlayBook
My Carrier: NA
Accepted Solution

ndk c/c++ tools: "size_t" undefined through c++ libs?

Hiya,

 

I'm getting a strange result when using "size_t" variable types in my applications. "size_t" is defined in the C libs <stdlib.h> and <stddef.h>. Typically when you're working with C++ though, its more common to include <cstdlib> and <cstddef>, which usually just act as references back to the C libs. Unfortunately, this doesn't work as expected (for me anyway) and I explicitly have to include the C libs, ie the C++ libs don't seem to do anything. It obviously has a trivial work around, but it took awhile to figure out and I'm still not sure why it doesn't work. I'm using NDK 2.0.1.

 

example:

 

(hello.h)

#include <iostream>

#include <cstdlib>

 

(hello.cpp)

#include "hello.h"

int main()

{

   size_t helloWorld = 0;

   std::cout << "helloWorld " << helloWorld << std::endl;

}

 

(compile)

qcc -Vgcc_ntox86 -lang-c++ -I/home/preet/bbndk-2.0.1/target/qnx6/usr/include/c++ -I/home/preet/bbndk-2.0.1/target/qnx6/usr/include -o hello.o -c hello.cpp

 

(output)

hello.cpp: In function 'int main()':
hello.cpp:5: error: 'size_t' was not declared in this scope
hello.cpp:5: error: expected ';' before 'helloWorld'
hello.cpp:6: error: 'helloWorld' was not declared in this scope
cc: /home/preet/bbndk-2.0.1/host/linux/x86/usr/lib/gcc/i486-pc-nto-qnx6.5.0/4.4.2/cc1plus error 1

 

If you replace <cstdlib> with <stdlib.h> in hello.h it'll compile fine... any ideas why this happens?

Please use plain text.
BlackBerry Development Advisor (Retired)
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: ndk c/c++ tools: "size_t" undefined through c++ libs?

Try std::size_t or using namespace std;

 

Stuart

Please use plain text.
BlackBerry Development Advisor (Retired)
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Device: developer
My Carrier: developer

Re: ndk c/c++ tools: "size_t" undefined through c++ libs?

Did this solve your issue?

Please use plain text.