IDE Custom C/C++ Local Build Environment

On my host machine I have many different development environment installed. From different make, cmake and python versions up to different versions of GNU tool chains. Adding them to the PATH environment variable on Windows is really a bad thing: instead I want to keep my PATH as clean as possible. If I need to set up a different environment with different tools, then I prefer to have a ‘local’ environment.

PATH Setting

If you have to maintain different projects and tool chains over time, then things can get complex. What I have found out that for example with Eclipse it is fairly easy to have a local environment, both on a workspace and project level.

Global and Workspace Settings

CDT provides a powerful way to provide global (workspace) related path settings. For example I can specify both the global or workspace ARM tool chain here:

Global and Workspace Path Settings

In a similar way I can set environment variables:

To check or update any other variables usable for the build, check out this setting page:

System Variables

Project CWD and PWD

In the project environment, there are the CWD and PWD variables:

CWD and PWD

The two variables are pointing to the Build Directory:

Build Directory

This sets the ‘current directory of the processes created’: so it means that for the above case the ‘Debug’ directory is the ‘current wording directory’ (CWD), for example for the compiler.

With this in mind, it is really a bad thing what is shown below with using an absolute path like below:

Absolute path settings

With this in mind, it is much better to use relative paths: they are not only shorter, they are more portable too:

relative include paths

Project PATH

Another very useful variable is the PATH one:

It is the same PATH variable you know from the base (Windows) operating system. So instead polluting your global host OS PATH with some entries, I can add my per-project PATH settings. For example if I want the project to use the tools for the Raspberry Pi, I can easily add that in front of the path:

The same way I can decide which cmake, Python or other tool I want to use, as usually I have multiple versions installed on my system.

Summary

There are multiple and different levels how to affect the environment or build variables.With Eclipse it is easy to set variables or settings on an IDE, workspace or project level. That way I can have a clean setup and separation between environments. Or I can just use that one special tool for my special project, without changing any global environment.

Happy setting 🙂

Links

Advertisement

4 thoughts on “IDE Custom C/C++ Local Build Environment

  1. To ensure project portability, it is preferable to define the installation location of local tools as CDT Build Variables at workspace preference level (specific to the individual user and their tools installation). For example:

    Variable: MY_TOOLS_LOC
    Value: C:\mytools

    Projects that need these tools can then prepend the location of these tools to the PATH environment variable for each build configuration of the project as follows:

    Variable: PATH
    Value: ${MY_TOOLS_LOC}/bin; ……..

    The project can then be shared between multiple users without modification. Each user provides their own definition of MY_TOOLS_LOC.

    Like

    • Hi John,
      yes, that’s a good approach, thanks for sharing! I use the same for referencing different depending project locations, using CDT Build variables to point to the source/library location: that way each user can have its own location of the library, plus it allows quick and easy switching between versions.

      Like

  2. Hi Erich – Liviu Ionescu’s xPack approach might also be of interest as it facilitates the use of specific tool versions on a per-project basis whatever build approach is used (command line Makefile, Eclipse GUI, VSCode GUI etc.).

    https://xpack.github.io/

    Like

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.