Creating a Library Project as an Object Code – KBA90606 | Cypress Semiconductor
Support & Community
Creating a Library Project as an Object Code – KBA90606
How do you protect the source code and still maintain the ability to use the code blocks in PSoC® Creator™ projects?
You can create a code in the form of an object code in PSoC Creator. The steps below show how to create a library project and then use the library project in an application project without exposing the source code of the library project.
Create a library project.
Figure 1. Create a Library Project
Click the Source tab in the PSoC Creator Workspace Explorer.
Figure 2. Source Tab in Workspace Explorer
Add the cytypes.h file under Header Files. Copy this file from “
\Cypress\PSoC Creator\3.0\PSoC Creator\psoc\content\CyComponentLibrary\CyComponentLibrary.cylib\cy_boot_v4_0\PSoC3\API”. Note that the path may change depending on the version of the PSoC Creator and cy_boot Component. This file is needed because many of the data types (such as uint8) are defined in this file. This file uses the macro CY_PSOC3, but this macro value is defined only when you select the device as a specific family of PSoC (PSoC 3, PSoC 5LP, etc.). Since this is a library project, you do not select a device. You assign a value to this macro manually. If you are building the library for PSoC 3, then assign the macro CY_PSOC3 a value of “1”, and the other macros CY_PSOC4 and CY_PSOC5 a value of ”0”. Comment out the line #include in the cyfitter.h file, because the fitter file is generated only in the application project (which is a normal project and not a library project).
Figure 3. The cytypes.h File
Add the source code as multiple .c files under Source Files and write the source code.
Figure 4. Source Code
Create a header file that will include all the function prototypes and extern variables for the source code.
Figure 5. Header File
Build the library project. Build it in both debug and release modes so that the library is created for both debug and release modes.
Figure 6. Release and Debug Modes
Back up the library project as development code in your choice of location. Delete all the source code. Because the library is compiled in the previous step, you can delete the source. Do not delete the header file Header01.h, which contains all the function prototypes and extern declarations. At this point, the source code exists only in the form of object code. Because this library is now in object code form, it can be used in any application project without exposing the source code.
Figure 7. Delete the Source Code
Use the library in your application project. In your application project, add dependency to the library project.
Figure 8. Dependency to the Library
Copy the header file Header01.h into the application project’s folder (for example, “ApplicationProject.cydsn”). Add the header file to the application project. This is how the application project will obtain the function prototypes and the extern declarations.
Figure 9. Copy the Header File into the Application Project
Use the library functions in the application project. Just include the Header01.h file in the file where the library code is used.
Figure 10. Use the Library