disappearing #includes

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

cross mob
JiAs_4080261
Level 1
Level 1
5 replies posted First reply posted First question asked

OK, I am feed up with having to add back about 15 lines of  #includes of my personal functions in the form of #include statements to the bottom of the project.h file.

Most of the time everything is fine and the #includes are still there.

But the other times they disappear and cause errors.

I have saved all after adding the #include statement.

I have tried to place the #includes in the main.c file but they do not work as expected, I have found they only work in the project.h file.

I believe this mostly happens when I change the TopDesign.cysch design.

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

Hi,

Reading this discussion, I wonder if you specified the include directories in the Build Settings?

One of the bad behavior of PSoC Creator is that even we include a header in the project, the project does not recognize the include directory for that file.

So we need to specify or add that include file in the Build Settings.

For example, one of my sample has relatively "many" files (headers and sources)

Re: MCU Tester, a Swiss Army Knife for PSoC (CY8CKIT-044 version)

And since I don't want to place too many files in the flat project folder,

I reorganized the folder structure like below

=======================

<project folder>/

codegentemp/

CortexM0/

Export/

Generated_Source/

sources/ <--- folder for additional sources and headers

TopDesign/

CLEAN.log

cyapicallbacks.h

func_list.c

func_list.h

main.c

...

<project>.cyprj

...

REBUILD.log

souces/

adc/

adc_utils.c

adc_utils.h

gpio/

gpio_utils.c

gpio_utils.h

i2c/

i2c_api_utils.c

i2c_api_utils.h

i2c_utils.c

i2c_utils.h

mem/

mem_utils.c

mem_utils.h

pwm/

pwm_utils.c

pwm_utils.h

spi/

spi_utils.c

spi_utils.h

tty/

tty_utils.c

tty_utils.h

=======================

Workspace Explorer shows

Note: I added "folders" manually and organized the files manually.

         But this does not let PSoC Creator know where those headers are

         even it recognizes where those sources files are....

001-workbench.JPG

So I needed to specify include directories by using "Build Settings"

I usually open it from right-click the project name -> Build Settings... like below,

but you can also invoke it from the menu Project > Build Settings...

002-build-settings.JPG

In the Build Settings dialog, select <project> / ARM GCC... / Compiler

Then we can see "Additional Inlucde Directories" in the "General" section.

003-build-settings-compiler.JPG

To modify (add/remove) directories, click the right side [...] button in the Additonal Include Directories

004-include-pathes.JPG

Then use [New] [Remove] [Down] [Up] buttons to add and prioritize your include directories

006-pathes.JPG

Hopefully, by doing this may improve your situation. (fingers crossed)

moto

P.S. I agree with Len-san about including a source file instead of a header.

Once I saw a user who had problems by including a source file.

I also recommend you to make it a header file or add a header file for that source file

and only include the header file.

View solution in original post

0 Likes
16 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

JiAs,

See the beginning of the project.h header comment:

/*******************************************************************************

* File Name: project.h

*

* PSoC Creator  4.3

*

* Description:

* It contains references to all generated header files and should not be modified.

* This file is automatically generated by PSoC Creator.

**/

Every time you modify ANYTHING in TopDesign (or perform a Clean before a build) project.h gets rebuilt.  All changes you make to the file gets thrown away.

Suggestion:

Create a file called main.h.  In this file place your custom #includes.

Len

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

I will try that once I get up to work.

Thanks.

Sent from Workspace ONE Boxer

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

I did this and the main.c file does not get included as part of the includes.

Before you ask, I did do the required ‘add’ header file in the right click of Header Files, to add the main.h

I then added #include “main.h” to the main.c file still with no joy.

These are the things I have done over the last 40+ years and they have always worked.

Why do they not work here.

What am I doing wrong?

Jim C. Ashby III – Sr. Engineer | Hurricane Mesa Test Facility | Mission Systems | K5JCA

COLLINS AEROSPACE

Shipping Address: 1 Mesa Rd, Virgin, UT 84779

Mailing Address: P.O. Box 1218, Hurricane, UT 84737, U.S.A.

Tel: +1 435 635 0268 | Mobile: +1 435 619 5333 | FAX: +1 435 635 7345

Jim.ashbyiii@collins.com<mailto:Jim.ashbyiii@collins.com> | collinsaerospace.com<http://www.collinsaerospace.com/>

CONFIDENTIALITY WARNING: This message may contain proprietary and/or privileged information of UTC Aerospace Systems and its affiliated companies. If you are not the intended recipient please 1) do not disclose, copy, distribute or use this message or its contents, 2) advise the sender by return e-mail, and 3) delete all copies (including all attachments) from your computer. Your cooperation is greatly appreciated.

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

Jim,

I'm not sure why it's not working for you.

I've attached a BlinkyLED project where I added main.h which includes additional .h files (main01.h,  main02.h, main03.h).  The main() function calls #defines in all the added .h files.

Unless I don't understand what you are trying to do, it appears to work fine.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.

I consulted with my college and we compared the Binky program to mine and have everything setup the same way, but I get no joy during a rebuild and run or debug command.

The only place I can place the #includes is in the project.h file.

I received permission to compress and send in the project file, but the site security will not allow me to send them to you.

The last file shows how I added the .h file.

Jim C. Ashby III – Sr. Engineer | Hurricane Mesa Test Facility | Mission Systems | K5JCA

COLLINS AEROSPACE

Shipping Address: 1 Mesa Rd, Virgin, UT 84779

Mailing Address: P.O. Box 1218, Hurricane, UT 84737, U.S.A.

Tel: +1 435 635 0268 | Mobile: +1 435 619 5333 | FAX: +1 435 635 7345

Jim.ashbyiii@collins.com<mailto:Jim.ashbyiii@collins.com> | collinsaerospace.com<http://www.collinsaerospace.com/>

CONFIDENTIALITY WARNING: This message may contain proprietary and/or privileged information of UTC Aerospace Systems and its affiliated companies. If you are not the intended recipient please 1) do not disclose, copy, distribute or use this message or its contents, 2) advise the sender by return e-mail, and 3) delete all copies (including all attachments) from your computer. Your cooperation is greatly appreciated.

0 Likes

Jim,

This makes absolutely no sense.  I've used PSoC Creator IDE for over 10 years.  I've never had a problem where I can create and load my own header files and these files remain with the project and can be referenced using #includes by other .c or .h files.

We're you able to download my example archive and get it to work?  If so, modify something in the TopDesign and recompile.  The #includes I put in main.h should be preserved.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.

I did get the BlinkLed project and it worked.

I have been programming for over 40 years and this is the first issue of this kind I have seen as well.

It is odd indeed.

I will try the process of changing the TopDesign and having the main.h ready to go and see if that resolves the issue.

It would be nice if the new project issuance would automatically create the main.h file as it does the main.c.

I will report back once I find out how to resolve the issue.

Respectfully and thankfully,

Jim C. Ashby III – Sr. Engineer | Hurricane Mesa Test Facility | Mission Systems | K5JCA

COLLINS AEROSPACE

Shipping Address: 1 Mesa Rd, Virgin, UT 84779

Mailing Address: P.O. Box 1218, Hurricane, UT 84737, U.S.A.

Tel: +1 435 635 0268 | Mobile: +1 435 619 5333 | FAX: +1 435 635 7345

Jim.ashbyiii@collins.com<mailto:Jim.ashbyiii@collins.com> | collinsaerospace.com<http://www.collinsaerospace.com/>

CONFIDENTIALITY WARNING: This message may contain proprietary and/or privileged information of UTC Aerospace Systems and its affiliated companies. If you are not the intended recipient please 1) do not disclose, copy, distribute or use this message or its contents, 2) advise the sender by return e-mail, and 3) delete all copies (including all attachments) from your computer. Your cooperation is greatly appreciated.

0 Likes

Jim,

The forum would appreciate the feedback if the issue gets resolved.  This is especially true in this bizarre situation.

About the #include with <> or "" =>  I found this explanation:

2.1 Include Syntax

Both user and system header files are included using the preprocessing directive ‘#include’. It has two variants:

#include <file>

This variant is used for system header files. It searches for a file named file in a standard list of system directories. You can prepend directories to this list with the -I option (see Invocation).

#include "file"

This variant is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the quote directories and then the same directories used for <file>. You can prepend directories to the list of quote directories with the -iquote option.

The argument of ‘#include’, whether delimited with quote marks or angle brackets, behaves like a string constant in that comments are not recognized, and macro names are not expanded. Thus, #include <x/*y> specifies inclusion of a system header file named x/*y.

However, if backslashes occur within file, they are considered ordinary text characters, not escape characters. None of the character escape sequences appropriate to string constants in C are processed. Thus, #include "x\n\\y" specifies a filename containing three backslashes. (Some systems interpret ‘\’ as a pathname separator. All of these also interpret ‘/’ the same way. It is most portable to use only ‘/’.)

It is an error if there is anything (other than comments) on the line after the file name.

Hope this helps.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
lock attach
Attachments are accessible only for community members.

OK, I moved all function definitions inside of the custom functions.

Now I get 72 warnings similar to the attached.

Jim C. Ashby III – Sr. Engineer | Hurricane Mesa Test Facility | Mission Systems | K5JCA

COLLINS AEROSPACE

Shipping Address: 1 Mesa Rd, Virgin, UT 84779

Mailing Address: P.O. Box 1218, Hurricane, UT 84737, U.S.A.

Tel: +1 435 635 0268 | Mobile: +1 435 619 5333 | FAX: +1 435 635 7345

Jim.ashbyiii@collins.com<mailto:Jim.ashbyiii@collins.com> | collinsaerospace.com<http://www.collinsaerospace.com/>

CONFIDENTIALITY WARNING: This message may contain proprietary and/or privileged information of UTC Aerospace Systems and its affiliated companies. If you are not the intended recipient please 1) do not disclose, copy, distribute or use this message or its contents, 2) advise the sender by return e-mail, and 3) delete all copies (including all attachments) from your computer. Your cooperation is greatly appreciated.

0 Likes

Jim,

Is   #include "GLOBALS.c"  allowed?

It's not common to use a .c file as an include.  This is because functions in .c files will get called multiple times during the pre-processing and compile phases.

Not knowing what is in GLOBALS.c, the warning you are getting are due to not having the prototype for the function being called referenced before the function call.

Another suggestion:

Place the  #include "project.h"  as the first include call.

This is because there are Cypress structs and defines that might be useful in user-defined function calls.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Reading this discussion, I wonder if you specified the include directories in the Build Settings?

One of the bad behavior of PSoC Creator is that even we include a header in the project, the project does not recognize the include directory for that file.

So we need to specify or add that include file in the Build Settings.

For example, one of my sample has relatively "many" files (headers and sources)

Re: MCU Tester, a Swiss Army Knife for PSoC (CY8CKIT-044 version)

And since I don't want to place too many files in the flat project folder,

I reorganized the folder structure like below

=======================

<project folder>/

codegentemp/

CortexM0/

Export/

Generated_Source/

sources/ <--- folder for additional sources and headers

TopDesign/

CLEAN.log

cyapicallbacks.h

func_list.c

func_list.h

main.c

...

<project>.cyprj

...

REBUILD.log

souces/

adc/

adc_utils.c

adc_utils.h

gpio/

gpio_utils.c

gpio_utils.h

i2c/

i2c_api_utils.c

i2c_api_utils.h

i2c_utils.c

i2c_utils.h

mem/

mem_utils.c

mem_utils.h

pwm/

pwm_utils.c

pwm_utils.h

spi/

spi_utils.c

spi_utils.h

tty/

tty_utils.c

tty_utils.h

=======================

Workspace Explorer shows

Note: I added "folders" manually and organized the files manually.

         But this does not let PSoC Creator know where those headers are

         even it recognizes where those sources files are....

001-workbench.JPG

So I needed to specify include directories by using "Build Settings"

I usually open it from right-click the project name -> Build Settings... like below,

but you can also invoke it from the menu Project > Build Settings...

002-build-settings.JPG

In the Build Settings dialog, select <project> / ARM GCC... / Compiler

Then we can see "Additional Inlucde Directories" in the "General" section.

003-build-settings-compiler.JPG

To modify (add/remove) directories, click the right side [...] button in the Additonal Include Directories

004-include-pathes.JPG

Then use [New] [Remove] [Down] [Up] buttons to add and prioritize your include directories

006-pathes.JPG

Hopefully, by doing this may improve your situation. (fingers crossed)

moto

P.S. I agree with Len-san about including a source file instead of a header.

Once I saw a user who had problems by including a source file.

I also recommend you to make it a header file or add a header file for that source file

and only include the header file.

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

Hi,

Another thing bothers me was the errors

007-errors.JPG

This usually happens when you define an instance inside a header.

I usually recommend to declare only "extern" in a header and define the instance in the source file.

Something like

foo.h

================

#ifndef _foo_h_

#define _foo_h_

extern int foo_flag ;

extern int do_that(void) ;

#endif /* _foo_h_ */

================

foo.c

================

#include "project.h"

#include "too.h"

#define LED_ON 0u

#define LED_OFF 1u

int foo_flag = 0 ;

int do_that(void)

{

     UART_PutString("I'm sorry m(_ _)m \n\r') ;

     if (foo_flag) {

          LED_Write(LED_ON) ;

    } else {

          LED_Write(LED_OFF) ;

    }

}

================

And as you see in the foo.h above, we usually need to protect a header by using #ifndef type block or #pragma.

moto

0 Likes

moto-san,

You are correct.  The exception is if the header files are located in the project directory.  In that case, the project directory is the working directory and the include path does not need to be added.

Len

Len
"Engineering is an Art. The Art of Compromise."
lock attach
Attachments are accessible only for community members.

OK, I have everything in ONE FILE called main.

I have been programming for 40+ years with embedded “C” and tried all of the procedures to separate custom function calls and nothing works.

PSoC must use a different format.

Would you point me to a PSoC document which will assist me in separating my custom functions?

Jim C. Ashby III – Sr. Engineer | Hurricane Mesa Test Facility | Mission Systems | K5JCA

COLLINS AEROSPACE

Shipping Address: 1 Mesa Rd, Virgin, UT 84779

Mailing Address: P.O. Box 1218, Hurricane, UT 84737, U.S.A.

Tel: +1 435 635 0268 | Mobile: +1 435 619 5333 | FAX: +1 435 635 7345

Jim.ashbyiii@collins.com<mailto:Jim.ashbyiii@collins.com> | collinsaerospace.com<http://www.collinsaerospace.com/>

CONFIDENTIALITY WARNING: This message may contain proprietary and/or privileged information of UTC Aerospace Systems and its affiliated companies. If you are not the intended recipient please 1) do not disclose, copy, distribute or use this message or its contents, 2) advise the sender by return e-mail, and 3) delete all copies (including all attachments) from your computer. Your cooperation is greatly appreciated.

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

Hi,

I'm sorry for hearing your troubles.

As far as I know of, PSoC Creator is using GNU compiler,

so the format won't be special.

Let me list what I noticed from your information.

By seeing the file, 2020-09-18_8-11-01.pdf, I think that you were very close.

Only 7 functions (or external variables) were defined multiple times.

I suppose this is caused by

(1) having entity of the function in some headers

or

(2) you might have functions with the same name in multiples files.

If (1) is the case, move the entity into the appropriate .c file and just define the prototype in the header files.

If (2) is the case, rename some of the function(s) or declare the function as "static"

By seeing the file 2020-09-18_9-13-16.pdf

I would avoid including anything before the "project.h"

And I would avoid including .c file, so if you need to include "GLOBALS.c"

I would create "GLOBALS.h" which has only extern variable or function prototypes

and include it after "project.h".

And as many functions were warned to be "implicit declaration",

I think that you need to include "main.h" after "project.h"

I also have been programming 40+ years,

but I'm making mistakes almost everyday,

so I would state myself still a learner.

moto

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

Looking at this main.h file, you will see all of the custom #includes.

Should I be using the #include <ARMED.h> instead f #include “ARMED.h” format?

If I copy this group of includes into project.h file everything works.

Go figure.

Jim C. Ashby III – Sr. Engineer | Hurricane Mesa Test Facility | Mission Systems | K5JCA

COLLINS AEROSPACE

Shipping Address: 1 Mesa Rd, Virgin, UT 84779

Mailing Address: P.O. Box 1218, Hurricane, UT 84737, U.S.A.

Tel: +1 435 635 0268 | Mobile: +1 435 619 5333 | FAX: +1 435 635 7345

Jim.ashbyiii@collins.com<mailto:Jim.ashbyiii@collins.com> | collinsaerospace.com<http://www.collinsaerospace.com/>

CONFIDENTIALITY WARNING: This message may contain proprietary and/or privileged information of UTC Aerospace Systems and its affiliated companies. If you are not the intended recipient please 1) do not disclose, copy, distribute or use this message or its contents, 2) advise the sender by return e-mail, and 3) delete all copies (including all attachments) from your computer. Your cooperation is greatly appreciated.

0 Likes