How to make a static library file怎样生成静态库文件

公告

大中华汽车电子生态圈社区并入开发者社区- 更多资讯点击此

Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Sophie_Wang
Level 4
Level 4
Distributor - Zenitron(GC)
25 replies posted 10 replies posted 5 replies posted

Hi CY Friend,

自己工程里的算法不想给源码,怎样将.c .h生成一个静态库文件,请问CY 有文档吗?

谢谢

sophie

0 点赞
1 解答

sophie,

The KBA listed earlier, has you place the library code in a Library project (.cylib).  Once you are happy with the code (it performs to your expectations) you compile the code under all the CPUs you wish to use the code.  For example the CortexM4, CortexM0+, etc.

To do so, select the library project and then the Build Settings...

pastedImage_0.png

Select the Processors:  then "Apply".  Remember, different PSoC might be using different CPUs.

pastedImage_1.png

If you have any special Build options that need to be used, set them for each Processor and Build configuration (Debug or Release).

pastedImage_0.png

Then "Apply" when you are all finished.

You can now generate your library code for all Processors you selected.

pastedImage_1.png

Change the Build configuration from "Debug" to "Release" (or visa versa) and rebuild.

If no errors occur during the build, you will have directories with your object code (.o) files for each Processor selected:

pastedImage_2.png

        pastedImage_3.png

and each Build configuration selected

                   pastedImage_5.png

Here is the output for each Processor/Build configuration.  The files with the .o are the ones desired for the library to be shared.

                              pastedImage_6.png

Next you can create an archive of the Library to share with others.

pastedImage_7.png

Select "Complete" before selecting "Archive".   Minimal will not include the directories where the .o files are compiled.

pastedImage_9.png

It will create the library archive.  Note:  This archive will include the source code (.c) files.

Lastly you want to remove the source code files from the archive.  To do so, go into the archive and delete all the files with .c extension.

NOTE:  You must leave the .h files.   These files are needed by the user of the library to access the library functions, global variables and any #defines needed.

I hope this helps.

Len

Len
"Engineering is an Art. The Art of Compromise."

在原帖中查看解决方案

0 点赞
3 回复数
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Sophie,

Creating a Library Project as an Object Code – KBA90606

Len

Len
"Engineering is an Art. The Art of Compromise."
0 点赞
Sophie_Wang
Level 4
Level 4
Distributor - Zenitron(GC)
25 replies posted 10 replies posted 5 replies posted

Hi Len,

If I need to use generated source code, what should I do ?

Thanks

sophie

0 点赞

sophie,

The KBA listed earlier, has you place the library code in a Library project (.cylib).  Once you are happy with the code (it performs to your expectations) you compile the code under all the CPUs you wish to use the code.  For example the CortexM4, CortexM0+, etc.

To do so, select the library project and then the Build Settings...

pastedImage_0.png

Select the Processors:  then "Apply".  Remember, different PSoC might be using different CPUs.

pastedImage_1.png

If you have any special Build options that need to be used, set them for each Processor and Build configuration (Debug or Release).

pastedImage_0.png

Then "Apply" when you are all finished.

You can now generate your library code for all Processors you selected.

pastedImage_1.png

Change the Build configuration from "Debug" to "Release" (or visa versa) and rebuild.

If no errors occur during the build, you will have directories with your object code (.o) files for each Processor selected:

pastedImage_2.png

        pastedImage_3.png

and each Build configuration selected

                   pastedImage_5.png

Here is the output for each Processor/Build configuration.  The files with the .o are the ones desired for the library to be shared.

                              pastedImage_6.png

Next you can create an archive of the Library to share with others.

pastedImage_7.png

Select "Complete" before selecting "Archive".   Minimal will not include the directories where the .o files are compiled.

pastedImage_9.png

It will create the library archive.  Note:  This archive will include the source code (.c) files.

Lastly you want to remove the source code files from the archive.  To do so, go into the archive and delete all the files with .c extension.

NOTE:  You must leave the .h files.   These files are needed by the user of the library to access the library functions, global variables and any #defines needed.

I hope this helps.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 点赞