How to use a third party shared or static library in a Cascades C++ project

by Retired on ‎09-12-2012 02:02 PM (8,988 Views)
This article demonstrates how to use third party shared or static libraries in a Cascades™ C++ project. There are two parts for this task:
1) Compiling and linking the Cascades C++ project code with the third party library.
2) Deploying the third party shared library to the target if the libraries are dynamically linked.
 
This article assumes that you have a Cascades C++ project created using the BlackBerry® Native SDK that will need to use third party libraries
 
The examples shown in this article pertain to Mac/Linux®; Windows® users will need adjust the file path for the library files.
 
 
Part A:  Configure the Cascades C++ project to compile and link with the third party libraries

 

  1. Edit the .pro file to update the INCLUDEPATH to add the path of the header files of the pre-built header libraries.
 INCLUDEPATH += <Path to the lib header files>

Note: if your .pro does not define INCLUDEPATH, you just add this line to .pro file.

 

 

2. Edit the .pro file to update the LIBS to add the pre-built libraries.

 

 

LIBS += -L<path to the  libs>  -l<lib name>

 

for example: if your object file is “/usr/someuser/workdir/libdummy.so”,

  

 LIBS += -L/usr/someuser/workdir/  -ldummy

 

If you want to statically link with this lib (assuming you have the static version of lib under the same location), you will need to add the "-Bstatic" compiler flag for this lib and append "-Bdynamic \" at the end so that other libs will still be linked dynamically.

 

LIBS += -Bstatic  -L<path to the  libs>  -l<lib name>   -Bdynamic  \

 

for example: if your object file is “/usr/someuser/workdir/libdummy.a”,

  

 LIBS += -Bstatic -L/usr/someuser/workdir/  -ldummy -Bdynamic \

 

 

Part B: Bundle the third party shared libraries with the app to be deployed to the target.

 

If the third party libs are dynamically linked, you will need to update bar-descriptor.xml file to add the shared libs to be bundled with the app.

 

This is achieved as follows:

 

1. From the qde, right click the project, select Configure->Add Library...

 

KB5.png

 

 

2. choose  “External Library” for Library Origin, press Next

 

 KB7.png

 

3.  Add the file path for the shared libraries accordingly.

 KB6.png

 

 

4 . Double check  the  bar-descriptor.xml file to make sure the environment var  “LD_LIBRARY_PATH”  contains “app/native/lib”

 

Ex.:

<env var="LD_LIBRARY_PATH" value="app/native/lib:/usr/lib/qt4/lib"/>

 

 

An Alternative method of bundling third party libs:

 

You can manually add the shared lib files to the project “assets”,  then manually edit the value of “LD_LIBRARY_PATH" in the bar-descriptor.xml file to contain the path pointing to the bundled shared lib files.

 

For example, if you copy shared lib files to the “assets/myLib”, then, you will have

 

<env var="LD_LIBRARY_PATH" value=" app/native/assets/myLib:/app/native/lib:/usr/lib/qt4/lib"/>

 

 

Related Articles

How to create a shared or static library to be used in other Cascades C++ projects