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
Highlighted
Super Contributor
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT
Accepted Solution

How to combine Cascade C++ code with Native C code in one project?

Purpose: Using Cascade C++ video camera sample with Native C sensor log.

                  and Using Cascade C++ UI function with Native C sensor function.

 

Problem: After putting Cascade C++ code into Native C code, the library shows unresolved inclusion.

 

Question: How to combine Cascade C++ code with Native C code in one project?

 

Minimum code:

#include<stdio.h>
#include <stdlib.h>

#include "printf.h"

#include <bb/cascades/Application>
#include <QtCore/QLocale>
#include <QtCore/QTranslator>

#include "hellovideocameraapp.hpp"

using ::bb::cascades::Application;

 

int main(void) {Application app( argc, argv);

     new HelloVideoCameraApp(&app);

     return app.exec();

     printfhw();
     printf("Hello again %d", hwnum);
     return EXIT_SUCCESS;
}

 

 

-Fight with BB10
Developer
Posts: 16,851
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to combine Cascade C++ code with Native C code in one project?

i would take a cascades project and add the c code there.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 60
Registered: ‎05-03-2013
My Device: Z10
My Carrier: Rogers

Re: How to combine Cascade C++ code with Native C code in one project?

Like the other person said, start a cascades project and add your C/C++ to it.  This will set you up to use cascades and then you can bring in whatever C/C++ libraries nd functions you need (remember the app isn't root, though).

 

Also have to remember that this is an embedded device with no serial debug port or console so if you need output you need to get creative and make yourself something like a label you can use to dump output.

 

You can get console out via the debugger, though, I should mention.  Just use fprintf(stderr,"text to print");

Super Contributor
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT

Re: How to combine Cascade C++ code with Native C code in one project?

Both of you describes to use Cascasde to call C program.

 

Could you tell me how to do it?

I could not find any sample how to using C++ to call C function.

 

 

-Fight with BB10
Developer
Posts: 60
Registered: ‎05-03-2013
My Device: Z10
My Carrier: Rogers

Re: How to combine Cascade C++ code with Native C code in one project?

You'd just add the header and call the funciton as you'd normally call a C function in C++.

 

You'll need to provide more details as to what you are trying to accomplish.  As it stands it looks like you want to run some C code in a cascades application.  You are more than welcome to do this, there's nothing stopping you.

 

Cascades projects are C++ projects by default.  You don't even need to use QML and can do everything in straight C++.

 

Cascades IS C++ and C and C++ get along quite well, hence the answer we gave.

 

We can't give exmamples because all you need to do is create a new cascades project in the IDE and it will generate the default files for you which are C++.  Just add your headers and whatnot and start coding.

Super Contributor
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
My Carrier: TT

Re: How to combine Cascade C++ code with Native C code in one project?

Thanks  mmarion.

 

The key is to have .c file and extern "C" in Cascade project.

 

The mini code is to share solution.

 

extern "C" int hwnum;
extern "C" void printfhw( );

 

 

int main(int argc, char **argv)
{

   printfhw();
   printf("Hello again %d", hwnum);

}

-Fight with BB10