Environment variables as include path

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

cross mob
PaSw_2578827
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

We're trying to create a single project template that can run on multiple machines and reference a set of common libraries without requiring manual intervention to set dozens of include paths on every machine individually. The ideal solution is to simply have each user create an environment variable with the same name that points to the library parent directory for their specific machine.  

Is there a way to pass a system environment variable as an include path to the ARM-GCC compiler when it is invoked via PSoC Creator? From the command line I can just run

 

arm-none-eabi-gcc -I%MY_PATH% main.c

 

This evaluates just fine, however when invoked from within PSoC Creator MY_PATH does not get evaluated (I have verified that it does exist within the environment of the application). My guess is that it's something to do with the way in which PSoC Creator is spawning the app, it's not simply invoking a command line and it's passing the variable as a literal.

Alternatively is there a way to manually create a custom PSoC Creator build macro which does get evaluated before being passed to the compiler? (Such as ${OutputDir}, ${WorkspaceDir} etc.) 

For reference setting C_INCLUDE_PATH as a system variable does work but it's not ideal as it will also pull those include directories into every other unrelated project built using any GCC version.

0 Likes
1 Solution
Gautami_12
Moderator
Moderator
Moderator
50 likes received 100 solutions authored 250 replies posted

Hi @PaSw_2578827,

Apologies for the delay in reply.

I tried to recreate this issue:-

In system environmental variables. At first, I added the variable name as MY_PATH and set the header file location in the variable value section.

Gautami_12_0-1661276625898.png

 

I checked it in the command prompt. It was pointing to the correct location.

Gautami_12_1-1661276626425.png

 

I created a project and tried to include a custom header file.
Yes, If we add the path directly the header file is recognized by the compiler.

Gautami_12_2-1661276626323.png

 

 

But if we add the environmental variable, the header file is not recognized. The compiler actually receives the string %MY_PATH% instead of the value of that variable. 

Gautami_12_3-1661276626598.png

Warm Regards,
Gautami J

View solution in original post

0 Likes
4 Replies
Gautami_12
Moderator
Moderator
Moderator
50 likes received 100 solutions authored 250 replies posted

Hi @PaSw_2578827,

"Is there a way to pass a system environment variable as an include path to the ARM-GCC compiler when it is invoked via PSoC Creator " can you please brief on this line?

Also, please attach the screenshot of the error message you are observing to better understand the issue.

Also please refer to:-

https://community.infineon.com/t5/Wi-Fi-Combo/Correct-way-to-add-include-directories-to-new-project/...

Warm Regards,
Gautami J

0 Likes

Well the error I'm getting is that it can't find the header file. If I enable verbose output from the compiler and look at what that is telling me, it's saying that it can't find the directory %MyPath% 

ignoring nonexistent directory "%MyPath%"

Which implies to me that it's getting the environment variable as a literal instead of the resolved path: 

The forum post you pointed me to is somewhat helpful at pointing me in a direction, but to be honest I feel like that question is a little further down the path I'm trying to get too. I'm not sure I fully understand the use of the *.mk files.

In a normal PSoC Creator project the makefiles are all internal or generated, is there a way for me to provide a *.mk file that PSoC Creator will use and won't edit? I know I can export the PSoC project to a makefile, but AFAIK PSoC Creator still doesn't use that makefile when it builds right? 

0 Likes

"Is there a way to pass a system environment variable as an include path to the ARM-GCC compiler when it is invoked via PSoC Creator " can you please brief on this line?


The include directory that I want to use is a system environment variable on my Windows machine names "MY_PATH". I want to use this as an include directory when executing the compiler. To do this from a commandline I just type: 

arm-none-eabi-gcc -I%MY_PATH% main.c

 

I had hoped that I could simple enter %MY_PATH% into the "Additional Include Directories" under Project > Build Settings > CM0+ > Compiler > General 

Unfortunately that does not work, the compiler actually receives the string %MY_PATH% instead of the value of that variable. 

0 Likes
Gautami_12
Moderator
Moderator
Moderator
50 likes received 100 solutions authored 250 replies posted

Hi @PaSw_2578827,

Apologies for the delay in reply.

I tried to recreate this issue:-

In system environmental variables. At first, I added the variable name as MY_PATH and set the header file location in the variable value section.

Gautami_12_0-1661276625898.png

 

I checked it in the command prompt. It was pointing to the correct location.

Gautami_12_1-1661276626425.png

 

I created a project and tried to include a custom header file.
Yes, If we add the path directly the header file is recognized by the compiler.

Gautami_12_2-1661276626323.png

 

 

But if we add the environmental variable, the header file is not recognized. The compiler actually receives the string %MY_PATH% instead of the value of that variable. 

Gautami_12_3-1661276626598.png

Warm Regards,
Gautami J

0 Likes