Andes Workshop http://forum.andestech.com/ |
|
How to generate a static library and how to use it http://forum.andestech.com/viewtopic.php?f=23&t=745 |
Page 1 of 1 |
Author: | HuJin [ Thu Oct 24, 2013 1:08 pm ] |
Post subject: | How to generate a static library and how to use it |
This article will take an easy example to illustrate how to generate a static library and how to use the generated static library in AndeSight. Section A: How to generate a static library Step1: Open AndeSight. Click "File" --> "New" --> "C Project", "Project Type" choose "Andes Static Library" --> "Empty Project", select toolchain and key in project name "StaticLib". As: Attachment: Step2: "StaticLib" is shown in Project Exploer. Right click on "StaticLib", select "New" --> "Source File", Key in the source file name "lib.c".As: Attachment: Attachment: Step3: Write the follow program code in lib.c: int add(int x,int y) { return x + y; } Attachment: Step4: Build the "StaticLib", the output is in the "Archives" folder. As: Attachment: Section B: How to use a static library in a Project It's an example of Hello World Project to use the library "libStaticLib.a". Step1: New a hello world project, as: Attachment: Step2: Copy the library file "libStaticLib.a" to "HelloWorld" Project, as: Attachment: Step3: Right click on "HelloWorld", select "New" --> "Header File", key in name "lib.h", and write the source coce in lib.h. As: Attachment: Attachment: Attachment: Step3: open file main.c, input the follow program: #include <stdio.h> #include <stdlib.h> #include "lib.h" int main(void) { int x, y; x = 6; y = 5; printf("add : %d\n", add(x, y)); return 0; } Attachment: Step4: This step is critical, we should do the setting to classifty the library path. Right click on "HelloWorld", select "Proproties", on Proproties Tab, click "C/C++ Build" --> "Settings" --> "Andes C Linker" --> "Libraries", put "StaticLib" in "Library"(not the name "libStatlicLib.a") and put "${workspace_loc:/${ProjName}}" in "Library search Path". As: Attachment: Step5: Build & Run the "HelloWorld" Project, we can see the program output is like our expects. Attachment:
|
Page 1 of 1 | All times are UTC + 8 hours [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |