Use shared libraries in bada programs

Source: Internet
Author: User

A shared or dynamic library is a binary file, including a set of callable C/C ++ methods. The code in the file is unlimited, which means that the code can be uploaded and executed at any storage location. Bada programs can upload and uninstall shared libraries. Interpreter(ld.exe) processes the upload and uninstall processes during the running time, and establishes a connection between the shared library destination and bada program.

The file explains how to create shared libraries, connect them to your app, and how to use these methods in your app.

Create a shared library. To create a shared library, you must first create a project for the library in bada IDE to configure different attributes for different concatenation. Then, you must define the library API. Finally, you must build a library binary file. For more information, see the following:

Create a library project:

To create a shared library project:

In bada IDE, select File> New> bada Application Project;

◆ If the bada Application Project option is invisible, make sure that you are using bada C ++.

◆ Enter the project name and select bada Shared Library project type.

◆ Click FINISH

Figure: create a shared library

Set C/C ++ Build Properties

You must set the build artifact settings for the new shared file. Different settings are required for the target and Simulator connection configuration.

To configure the build artifacts for Target-Debug:

◆ In bada IDE Project Explorer, right-click the shared library Project and select Properties;

◆ In the Properties window, select C/C ++ Build> Settings;

◆ On the Build Artifact key, enter and output the prefix lib and expand artifact.

When you use a shared library on the target device, the library file must start with "lib" by name.

◆ Enter OK.

The library file is named lib. so.

Figure: set Target-Debug build artifact

To configure the build artifacts for Simulator-Debug:

◆ In bada IDE Project Explorer, right-click the shared file library and select Properties;

◆ In the Properties window, select C/C ++ Build> Settings

◆ On the Build Artifact key, the input and output prefixes are lib, And the artifact extension name is dll ..

◆ Simulator runs in Windows. The dynamic library is a ". dll" file. Therefore, for Simulator, the default artifact extension of the dynamic library must be set to "dll ".

◆ Click OK.

The library file is named lib. dll.

Figure: Set Simulator-Debug build artifact

Define library API

You must publish the library API in the header file and define it in the corresponding. cpp file.

The following code snippet shows how to declare the library API for your program.

 
  1. // This method is exported from libDynaLib.so  
  2.  
  3. _EXPORT_ int OspfDynaLib(void);  
  4.  
  5. // Exported user-defined class  
  6.  
  7. class _EXPORT_ MyClass {  
  8.  
  9. public:  
  10.  
  11. MyClass(void){};  
  12.  
  13. virtual ~MyClass();  
  14.  
  15. void PrintMessage(void);  
  16.  
  17. }; 

Note: The Library methods or classes to be read outside the shared library must be announced using _ EXPORT _ macro.

Build Database

You must build a library project to generate a library binary file. In bada IDE, select Project> Build Project.

If the connection is successful, create a binary file for each configuration, as shown in the following table (libDynaLib. so, libDynaLib. dll. The binary file is in the workspace folder of the project, for example, C: \ bada \ 1.2.0 \ IDE \ workspace \ DynaLib \. Target-Debug \ libDynaLib. so.

Figure: generated library binary file

Connect the shared library to your program

To use the library output method in your bada program, you must connect the library to your program and place the corresponding header file in the program's. cpp file. In addition, you must define the library and search path to its location in the program project properties.

To set the library and search path in the project properties:

◆ In bada IDE Project Explorer, add the lib folder to your bada program Project;

◆ Copy the shared library binary file used for the target concatenation configuration to the newly created lib folder;

◆ To run the program on the Simulator, you must copy the binary file (. dll file) of the Simulator's concatenation configuration to the library path of the Simulator. For example, C: \ bada \ 1.0.0 \ Model \ Wave_LP1 \ Simulator \

◆ In Project Explorer, right-click the program Project and select Properties

◆ In the Properties window, select C/C ++ Build> Settings;

◆ Select the appropriate concatenation Configuration from the Configuration drop-down menu.

◆ In Tool Settings, select bada C ++ Linker> Miscellaneous.

◆ Add shared Libraries used in Libraries (-l;

◆ Add a library name without a prefix or a file extension name. For example, add the libDynaLib. so binary file as DynaLib;

◆ Check the default Library path ($ {PROJECT_ROOT}/lib) in the Library search path (-L. If not, the new lib folder is the search path.

◆ Click APPLY.

◆ Repeat Step 5-9 for other concatenation configurations.

◆ Save settings and click OK.

Figure: Library settings in a program project

Use the shared library Method

After you connect a shared library to a program, you can use the method defined by the library API in the program.

The following code snippet shows how to use the shared library.

 
  1. // Using the shared library methods   
  2. AppLog("Value from OspfDynaLib = %d",OspfDynaLib());  
  3. MyClass* obj = new MyClass;  
  4. obj->PrintMessage();  
  5. delete obj; 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.