How to include CyLib.h from a Library Project

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

cross mob
ricardoquesada
Level 4
Level 4
First solution authored 50 sign-ins 25 replies posted

Hi,

I have a workspace that has 2 "Design projects" and one "Library project".

The "Library project" is that one that contains the shared code. And from I'd like to call `CySysTickStart()` from it.

That functioned is declared in "CyLib.h", but I cannot include it from my "Library Project".

 

Question: How do I include CyLib.h (or for the matter, any other Cy* file  / cmsys* file) from a Library Project?

(Note: Those files seems that they get auto-generated by the "Design Project").

0 Likes
1 Solution

ricardo,

I guess I'm a bit confused.

Is your "Library project" a project with a shareable library code?   

Or is it an Cypress "Library Project"?   This is a special type of project that allows you to share library code with your other projects and with other people.  It also can contain custom components

If it is "a project with a shareable library code" then it is simplier.

Before I provide this method, with a name of "CyLib.h" you have a problem.   When you create your own project like DesignA or DesignB, it automatically creates a "CyLib.h" file in the "Generated_Source\cy_boot" directory of each of your projects.   

Since the C compiler will only allow one file with a specific name, you will need to rename your "shared" library .h file   "cyapi.h" is a decent name.   For the instructions below, let's use "cyapi.h" and the shared source file "cyapi.c"

To locally include the "cyapi.h"  into DesignA and DesignB there are two ways.

Method A: Copying the shared lib

  • On your workspace, expand the Library Project and DesignA.  
  • Click on cyapi.h in your Library Project and Copy (Ctrl-C)
  • Go to the "Header Files" directory of DesignA and Paste (Ctrl-V) on tis directory.
  • In the DesignA files that need the library, add "#include "cyapi.h"
  • Click on cyapi.c in your Library Project and Copy (Ctrl-C)
  • Go to the "Source Files" directory of DesignA and Paste (Ctrl-V) on tis directory.

DesignA should now have a copy of your shared library .h and .c files

There are a potential problem.

  • If you change the original cyapi.h and/or cyapi.c, it will not be reflected in DesignA.

Method B: Add the shared lib without Copying it

  • On your workspace, expand DesignA.  
  • Go to the "Header Files" directory of DesignA and Right-click and select  "Add/Existing Item..."
    Len_CONSULTRON_0-1634655998200.png

     

  • In the "Open" dialog window that appears, find the cyapi.h" in Library Project.
  • In the DesignA files that need the library, add "#include "cyapi.h"
  • Go to the "Source Files" directory of DesignA and Right-click and select  "Add/Existing Item..."
  • In the "Open" dialog window that appears, find the cyapi.c" in Library Project.

DesignA should now have reference to your shared library .h and .c files.

This reference instead of a copy allow you to change the .h and .c files in the Library Project WITHOUT needing to update them in the Design projects.

 

There is another method that modifies the BUILD definition for each Design Project.  This is a bit more complicated to get correct.

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

View solution in original post

0 Likes
4 Replies