Use static libraries in bada programs

Source: Internet
Author: User

The static Library collects the target files and creates them using the ar (archive) program. The binary file of the static library ends with the extension name ". The static library allows users to connect to the program without re-editing the code, thus saving the editing time.

This article describes how to create static files, connect them to your program, and use them in your program. Recommended reading: using shared libraries in bada programs)

Create a static library

To create a static library, you must first create a project for the library in bad IDE, and then define different attributes for different concatenation configurations. Then, you must use the library API. Finally, you must build the library binary. For more information, see the following section:

Create a library project

To create a static Library:

◆ 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 the bada Static Library project type;

◆ Click Finish

Figure: creating a static library

Set C/C ++ Build attributes

You must set the build artifact for the new static library. These settings are the same as those configured for Simulator and target concatenation.

To set the build artifact:

◆ In bada IDE Project Explorer, right-click the static library Project and select Properties.

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

◆ On the Build Artifact key, check whether the output prefix is lib and whether the extension name of artifact is.

◆ Click OK.

The library file is named lib. ..

Figure: settings in build artifact

Define library API

You must publicize the library API in the header file and define them in the corresponding. cpp file.

The following code snippet shows how to publish a library API for your program.

 
 
  1. // This method is archived in libStatLib.a  
  2.  
  3. int StatLibMethod(void);  
  4.  
  5. // User-defined class archived in libStatLib.a  
  6.  
  7. class MyClass {  
  8.  
  9. public:  
  10.  
  11. MyClass();  
  12.  
  13. virtual ~MyClass();  
  14.  
  15. void PrintMessage(void);  
  16.  
  17. }; 

Note: The Library methods and classes to be archived must be declared as General C ++ declarations.

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, each configuration generates a binary file, as shown in the following figure (libStatLib. ). The binary file is located in the workspace folder of the project. For example, C: \ bada \ 1.0.0 \ IDE \ workspace \ StatLib \. Target-Debug \ libStatLib..

Figure: generate a library binary file

Connect the static library to your program

To use the library method in your bada program, you must connect the library with the program and prevent the corresponding header file from being 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, 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 the static library used in Other objects, including the path details with the Library name.

◆ Click Apply.

◆ Repeat steps 3-6 to configure other connections.

◆ Save settings and click OK.

Figure: Library settings in a program project

Static library Method

After you connect a static library to a program, you can use the methods defined in the library API in the program.

The following code snippet shows how to use a static library.

 
 
  1. // Using the static library methods  
  2.  
  3. MyClass* obj = new MyClass;  
  4.  
  5. obj->PrintMessage();  
  6.  
  7. 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.