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.
- // This method is archived in libStatLib.a
-
- int StatLibMethod(void);
-
- // User-defined class archived in libStatLib.a
-
- class MyClass {
-
- public:
-
- MyClass();
-
- virtual ~MyClass();
-
- void PrintMessage(void);
-
- };
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.
- // Using the static library methods
-
- MyClass* obj = new MyClass;
-
- obj->PrintMessage();
-
- delete obj;