Building with external source code on PSoC 6 in PSoC Creator

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

cross mob
BrBr_1320441
Level 3
Level 3
25 replies posted 10 replies posted 5 replies posted

Hi,

I am having a hard time getting my project to compile with my desired source tree.

My source tree looks like follows

/modules

---/lib1

------/include/lib1

------/source

---/lib2

------/include/lib2

------/source

/src

----/CreatorProject (and the normal directory structure for a creator project)

I am adding additional include directories as: -I ../../../modules/lib1/include ../../../modules/lib1/source

And then I am including them in my project source as:

#include <lib1/lib1header.h>

Creator is correctly seeing the header files, and so it is getting the function declarations as expected.

The problem is that GCC cannot find the function definitions, which means it isn't compiling the /source files.

I tried adding an Include library directory to the Linker, but obviously these aren't external libraries which need to be linked, they are source files that should be compiled. There isn't any option to add additional compilation targets through the build settings as far as I can tell. And I don't think there is any way to do file globbing through the gcc command line, so I don't think so it isn't as simple as adding "../../../modules/lib1/source/*.c"

If I add the files directly to my workspace (one source file at a time) it will compile correctly. This is however tedious and cumbersome, since some of these external libraries are heavily nested with a lot of .c files in many different folders, and I can't simply add an entire directory structure as far as I can tell.

So basically I can't figure out how to get it to see the /source files of each external module and compile those.

Thanks for any input!

0 Likes
1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Brian-san,

I'm sorry for missing your point.

Then I wandered searching better method for this...

as far as I could search, I could not find you a better approach.

One thing came to my mind is,

"IF" you are willing to  use the Modus Toolbox we can do it.

Note: I'm still a beginner with Modus Toolbox, the information may not be the best but.

For the usage of Modus Toolbox please refer to

ModusToolbox

or

ModusToolbox PSoC 6 SDK

What I tried was/were

(1) Start up Modus Toolbox (mine is v1.1)

000-workbench.JPG

(2) Then I select "New Application" in the bottom left "Start" pane.

A dialog for choosing target hardware appeared.

I selected the one with CY8C6247BZI-D54.

001-Choose-target.JPG

(3) For the starter application, I chose "BlinkyLCD"

002-Selecting-Blinky.JPG

(4) Summay was shown, I selected [Finish] button

003-Summary.JPG

(5) I selected New > Folder from the pop-up menu

004-New-Folder.JPG

(6) I selected "BlinkyLED_mainapp" for the parent folder

and named the folder "modules"

005-Folder.JPG

(7) modules folder was added in the BlinkyLED project

006-modules-folder-added.JPG

(8) On the module folder, with mouse right-click pop-up menu, I selected import...

007-import.JPG

(9) I chose "File System" for the resource type

008-Select-File_System.JPG

(10) Then Import dialog was displayed. I selected "Browse..." button

009-Import.JPG

(11) Then I located your project / modules

010-module-selected.JPG

(12) I checked the modules folder then selected the [Finish] Button

011-modules-checked.JPG

(13) The directory hierarchy was imported into the project!

012-modules-imported.JPG

Best Regards,

23-Oct-2019

Motoo Tanaka

View solution in original post

0 Likes
10 Replies
Rakshith
Moderator
Moderator
Moderator
250 likes received 1000 replies posted 750 replies posted

Hi BrBr_1320441

Including the source file directory in the GCC compiler directories might fix your issue. Please refer to the following thread and check if the steps mentioned solves your issue -

https://community.cypress.com/message/192974#192974

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes

Hi,

I mentioned in the first part of my post (not very clearly, sorry), but this is how I got my include paths to work correctly. Including the source code in the same way has no effect. What I would need is a section here on "Include External Source Directories." Perhaps I can compile these modules separately into a library and handle it with the Linker. It is a little cumbersome though, because I would need to recompile any time I pull in upstream changes.

Brian

0 Likes

Hi BrBr_1320441

Please share your project so that I can better understand the issue and figure out a solution for the same.

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes
lock attach
Attachments are accessible only for community members.

Ok.

Here is a project which is built exactly how I described the problem. I am not able to share the original project, but this is a minimal example on how to reproduce it. The comments I added should be clear to describe the problem. What do I need to do to have that project compile? Adding lib1/src to the include directories is not the solution.

In CMake, for instance, you would glob the files in that directory and add them to your target sources. I could alternatively (I think) compile these modules separately into a library and then handle it through the linker.

Ultimately I am looking to figure out how to do what the pdl and other generated source is doing. Those source files are being brought into the build from an external location and then compiled, that is what I want to do without needing to manually add them.

Brian

0 Likes
lock attach
Attachments are accessible only for community members.

Hi BrBr_1320441​,

The source files and header files were not included in the PSoC Project Source Files and Header Files. It needs to be included again in the PSoC Creator as shown -

pastedImage_0.png

To do this right click on 'Header Files' or 'Source Files' and click on 'Add' -> 'Existing Item' and select the files to be added.

I have also attached the project for your reference.

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes

Hi,

I am sorry, I think I am not explaining myself properly because this is not the solution I am looking for. Please let me know if I need to clarify more.

I know that you can manually add the source and header files to the Workspace Explorer, I mentioned that this was an alternative and it is how I am currently progressing.

However, you do not need to do this for headers. If you look at my comment in the main code, you will see that the function definitions are seen in the headers perfectly fine (without the headers manually added) because I added the include directories through Build Settings > CM4 ARM GCC > Compiler > Additional Include Directories. This works as expected and it works perfectly.

I want a way to do the same thing for external source because I am using externally tracked (large) projects in my design with many source files embedded in many source folders.

1) It is tedious to add every file as existing because you cannot properly add folders.

2) It clutters up my workspace explorer quite a bit and since I do not need to edit any of these sources I would prefer to not have them there at all.

I think I am simply discovering that this doesn't exist and I either have to continue as I am or I need to compile the source into a library and link it through the Linker settings (and recompile when I pull in changes.)

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I think what you are asking is something like below.

As being an old **nix programmer, I often needed to do this 😉

I think there are 2 or 3 step operation(s) required.

(1) Add Files in to project (including folder structure)

(2) Inform the compiler about additional include directories

(3) Inform the linker about additional lib directories (if there is/are additional lib*.a)

Now let me try with your attachment

Step 1

(1) Using select->project -> pop-up-menu Add > New Folder

I added

modules

modules/lib1

modules/lib1/include

modules/lib1/include/lib1

modules/lib1/src

modules/lib2

modules/lib2/include

modules/lib2/include/lib2

modules/lib2/src

000-Add-New-Folder.JPG

(2) Then added source and header to each folder using the Menu Add > Existing Items...

I added

moudles/lib1/include/lib1/lib1header.h

modules/lib1/src/lib1source.c

modules/lib2/include/lib2/lib2header.h

modules/lib2/src/lib2source.c

001-Add-existing-item.JPG

Now Step2

We must inform the compiler about additional include folder which we usually do -I<dir> option in CC

And for PSoC 6, we must know which compiler needs which header, or may be we can add them for both.

in the following sample, I only added to CM0+ compiler, may be you need add them to CM4 compiler, too.

(3) From the pop-up menu -> Build Settings...

003-Build-settings.JPG

(4) In the Build Settings Dialog, CM0+ ARM GCC .../Compiler/General

Select "Additional Include Directories" then select [...] button in the right side.

004-Additional-include-dire.JPG

(5) Additional Include Directories dialog shows up, select [New] Button

005-new.JPG

(6) A new field is added, again select [...] button to specify the folder

006-select.JPG

(7) Then using standard file select dialog, select the folder.

Here I selected "modules/lib/include".

Note: Sorry, My PC is setup for Japanese. (May be a good chance to learn Japanese..)

007-select-include.JPG

(8) Now "modules/lib1/include" folder has been added.

008-include-added.JPG

(9) Similarly added "moudels/lib2/include"

009-include-added.JPG

Then select [OK]

(10) In the Build Settings/Compiler/General, these folders have been added

010-include-added.JPG

Step 3

(11) If you have additional libraries, you may need to add library folders

Similar idea. (so let me skip the details)

011-additional-Lib-dir.JPG

If you need these source and header for CM4, please do the same for CM4 compiler.

Now the project should be compile-able.

Attached is your project modified with above method.

moto

0 Likes

Moto,

Thank you for your thoughtful reply. I am glad you are helping to address the problem for me. I will mention once more though that the step I am specifically trying to skip is step (1) that you laid out -- this is my primary issue. I am currently doing exactly as you suggest, and have been progressing with my work in that way. I am looking for a way to include those sources in a similar way that I included the include directory.

Essentially imagine that I have many external projects in my modules folder. Imagine that I do not develop those modules myself, but I am trying to include them in my project (FOSS libraries from github, for instance), but imagine that the structure includes about 100 folders with a nested structure, sometimes thousands of .c files. Let's pretend it is 1,000,000 source files (it isn't but just to make an extreme example).

Even if I spend the time to manually add them all, this is still problematic because the developers (of the external modules) can restructure their code (add files, remove them, merge, move, rename, etc) and it is very difficult for me to accommodate that each time I pull in changes. But again, I don't care about how the external project is developed. I just care about using it.

With the provided method, it will work until those changes occur and then I have to spend the time to repeat step (1). Not to mention the time it takes to add these just once, and then the fact that my workspace explorer gets very messy.

As an example, what I would do in CMake is something like:

FILE(GLOB lib1_sources ../../../modules/lib1/source/*.c)

FILE(GLOB lib2_sources ../../../modules/lib2/source/*.c)

target_sources(app PRIVATE ${creator_app_sources} ${lib1_sources} ${lib2_sources})

and then it is done. In scons I might do something similar:

lib1sources = Glob('../../../modules/lib1/source/*.c')

env.Program("app", lib1sources)

etc.

Unfortunately I don't know of a standard gcc command line switch that lets me do it just through the command line, so I was hoping there was some way to do it through Creator. I am happy to do it through a pre-build script as well if needed (can I just copy the source in the Generated Source folder??)

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Brian-san,

I'm sorry for missing your point.

Then I wandered searching better method for this...

as far as I could search, I could not find you a better approach.

One thing came to my mind is,

"IF" you are willing to  use the Modus Toolbox we can do it.

Note: I'm still a beginner with Modus Toolbox, the information may not be the best but.

For the usage of Modus Toolbox please refer to

ModusToolbox

or

ModusToolbox PSoC 6 SDK

What I tried was/were

(1) Start up Modus Toolbox (mine is v1.1)

000-workbench.JPG

(2) Then I select "New Application" in the bottom left "Start" pane.

A dialog for choosing target hardware appeared.

I selected the one with CY8C6247BZI-D54.

001-Choose-target.JPG

(3) For the starter application, I chose "BlinkyLCD"

002-Selecting-Blinky.JPG

(4) Summay was shown, I selected [Finish] button

003-Summary.JPG

(5) I selected New > Folder from the pop-up menu

004-New-Folder.JPG

(6) I selected "BlinkyLED_mainapp" for the parent folder

and named the folder "modules"

005-Folder.JPG

(7) modules folder was added in the BlinkyLED project

006-modules-folder-added.JPG

(8) On the module folder, with mouse right-click pop-up menu, I selected import...

007-import.JPG

(9) I chose "File System" for the resource type

008-Select-File_System.JPG

(10) Then Import dialog was displayed. I selected "Browse..." button

009-Import.JPG

(11) Then I located your project / modules

010-module-selected.JPG

(12) I checked the modules folder then selected the [Finish] Button

011-modules-checked.JPG

(13) The directory hierarchy was imported into the project!

012-modules-imported.JPG

Best Regards,

23-Oct-2019

Motoo Tanaka

0 Likes

Thank you for the reply, Motoo.

I had not considered Modus Toolbox but it looks like the best solution, thanks for the detailed procedure. This seems like the best approach that exists as far as I can tell. The only thing I will have to check is to see if it causes issues when files/folders are changed inside the modules folder. I will also have to decide if I am willing to give up the schematic component of Creator for this functionality.

I hope this functionality can one day be added to Creator.

Thanks again!

Brian