How to add an include directory based on environment variable in RHIDE without expansion? - c++

The REDHAWK IDE insists on expanding environment variables when creating the Makefile.am.ide file. For example, assume that $SRC_ROOT is /srcpath and I add an include path in the Path and Symbols window of the C/C++ section of my project as below:
${env_var:SRC_ROOT}/include
the generated Makefile.am.ide file contains:
rehawk_INCLUDES_auto = -I/srcpath/include
when what I really want is:
rehawk_INCLUDES_auto = -I$(SRC_ROOT)/include
This is important because this file is used by other team members that have different values for $SRC_ROOT. Currently we have to put the include path in Makefile.am, but then the IDE doesn't see the header files in the directory and sees errors for the code referred to in the missing headers.
Is there anyway to get RHIDE, to not expand the environment variables when it generates Makefile.am.ide?

Not exactly what you are looking for but you can always disable the auto-updates of the Makefile.am.ide by disabling the REDHAWK C++ auto-inclusion builder. This is in the projects properties in the Builders section.
This will allow you to add to Eclipse's Paths and Symbols section without the auto-inclusion builder picking it up and adding it to your Makefile.am.ide.
If you do choose to disable this builder you will then need to manage the addition of new source files on your own.

Youssef's answer is not a bad one, but I've come up with a different way to work around the problem. In Makefile.am, override the redhawk_INCLUDES_auto value to be what I what it to be:
include $(srcdir)/Makefile.am.ide
#Override the value from Makefile.am.ide that may be wrong!
override redhawk_INCLUDES_auto = -I$(SRC_ROOT)/include
This requires one to update any custom include directories in both the IDE and the Makefile.am file, but managing the source files is still automatic.
It still has the issue that the Makefile.am.ide file's contents will be different for other developers which complicates version control. So I don't consider this be a complete answer to the problem.

Related

IAR C Preprocessor include directories

I've been asked to make a small mod to some software that was written back in the mid naughties on IAR Embedded Workbench v3.3
I have had the original source files copied from an old machine to one I have been given for the task.
For the moment I am simply trying to get the software compiling. It took me a while to realise, or at least I thought I'd realised, that the reason it couldn't open various header files was that, incredibly, all the include paths were absolute, not relative.
So, I changed all the paths to be $PROJ_DIR$ relative, but then started to get different files that couldn't be opened. Then realised that the machine they gave me just happened to have a very similar directory structure to the original machine used and, amazingly, had quite a few of the same files in the directory structure of this machine I'm using as was on the machine used to compile the code originally.
I then thought, OK, I'll just check I have got my relative paths correct by choosing one of the header files it was complaining about not finding and putting, in the Preprocessor tab, an absolute path to the directory on this machine I'm using that contained the header file it wanted. However, that still wouldn't find the header file!
Finally, I put an absolute path in the c file to point to the desired header file.
#include "C:\absolute__Path\stdtyp.h"
And it compiled.
To confirm:
Putting C:\absolute__Path
in the Project | Options | C/C++ compiler | Preprocessor tab will not work if I just have:
#include "stdtyp.h"
in the c file.
I have used IAR in the past - not that much - but I have used it and I was sure that's where you set your include directories. So, am I wrong, or can there be something else that is overriding that path in the Preprocessor tab as described above?
Edit: I'm not wrong, after having slept on it, I decided to create a new project with random directories, subdirectories and header files. Sure enough, if I set and remove $PROJ_DIR$ referenced paths in the preprocessor tab, the new project compiles, then doesn't. So, there must be something, presumably in the ewp file that is borking it.
It turns out you can override the paths on an individual file by file basis. So, the rogue files had the paths overridden and had absolute paths.
Right click on the file in EW and select Options.
That then for most file shows a load of greyed out boxes. What I'd failed to do was thoroughly check all files. The few I'd randomly checked were greyed out, but some files had their properties overridden here with different (and absolute) paths put there.
At least now the project can be easily copied between machines having used relative paths.

Using multiple resource files in MFC project

I'm working in MFC (C++11)in VS2015 and I have a set of standalone GUIs that i'd like to use across multiple projects. I know this is possible by creating a .rc file that can be included in the main .rc file of each project based on this:
Using Multiple Resource Files
While conceptually I understand what it is describing, i can't find any example of creating the standalone .rc file and second resource file. I created a test resource header file that lives globally in my solution and tried to include it using Resource Includes, but it can't find it, even with the path. Can anyone point me to links or examples on how to set this up?
I have either .rci files, that are never used with the resource editor. They are used with #include freely.
Or I have special .rc files that contain standard symbols and messages, that are used over a larger set of projects.
I just simply add the second rc file to the project. This resource file is simply #include'ed into the main .rc file of the project.
To prevent errors in the project. This second .rc file is excluded from the build. In the solution explorer right click on the item. And set Exclude from Build to YES.
Take care about collisions of IDs.
Here is how I do it. If you drop the resource you would like to include on the resource folder in the solution explorer, it will show up as a separate and editable resource in your project
You will have to include the headers in your project that go along with them, of course. So watch out for collisions of your IDs. You may have to go to the new resource and use IDs that have been set aside by adjusting _APS_NEXT_XXX_VALUE. I've never used the 'Resources Includes..'. as described in TN035. I just checked and relative paths to bitmaps seems to work fine. Hope that helps.
I know two approaches of doing it. I will demonstrate it assuming you want it for the need of managing the fact your application supports several languages.
The first one is already described by user #xMRi, and depending on your configuration/platform you will include only the .rc in question. For example you have configurations:
en_GB
fr_FR
pt_PT
de_DE
and files
Project_en_GB.rc
Project_fr_FR.rc
Project_pt_PT.rc
Project_de_DE.rc
For getting this right, you will need to do Exclude from build on them all, except on the Configuration you have selected at the moment on the VS Toolbar combo. If you have fr_FR selected, do Exclude from build of all other .rc except Project_fr_FR.rc files and apply the same logic on every configuration.
The other is to have a VS project (vcproj) for each language, where each project contains the .rc file brlonging to it.
The projects
Project_en_GB
Project_fr_FR
Project_pt_PT
Project_de_DE
contain respectively
Project_en_GB.rc
Project_fr_FR.rc
Project_pt_PT.rc
Project_de_DE.rc
Here at work we use both (I never heard of .rci files before; we use the first with normal .rc files), depending on the project.

Xcode folders and groups confusion

I'm using Xcode (with C++) and my project layout (in the file system, not in Xcode) looks like this:
SubfolderA
-file_A_1, file_A_2
SubfolderB
-file_B_1, file_B_2
Right now I've set up this structure in Xcode via groups. And so, when I want to include file_A_2 in file_B_1, I write #include "file_A_2" in file_B_1.
Is there some way to make an inclusion look like #include "/SubfolderA/file_A_2", so that I can easily see to what directory/subfolder an included file belongs?
One way to see what's going on is to look at the Build Log and expand the line for compiling sourcefile.m. Look at the -I options being passed to the compiler.
If it's not to your liking you can add the source tree in the Build Settings > Header Search Paths to include $(ProjectDir)/srcroot and make it recursive, which saves you from adding each sub-folder individually.
In my experience this has never been necessary, however, as far as I can remember.
As far as the Xcode folders are concerned, if the top-level source folder is added then all sub-folders are automatically added when you add them to the filesystem, saving the hassle of keeping them in sync. You might need to add the top-level folder under the Source Files group for this to work, however.
Surprisingly, in Xcode's Build Settings I've added to User Header Search Paths non-recursive path to my project. This solved my problem.
I ended up here when I was having an issue with XCode while trying to include a header in a group by doing
#include "MyGroup/MyHeader.h"
Turns out the project structure and the file system weren't in sync, so I just had to remove my group from the project, put it in the correct place in Finder, then drag and drop it back into the project in the correct place and it worked for me.
I'm not sure if this is necessary or not, but I also have already set up my app's working directory because I am doing some game programming and need to be able to load in .png and make textures.

Use eclipse build variables to create project include directories, in C++

I have a C++ project in Eclipse which the base part of all include directories is different depending on a chosen platform. For example, including include/cTable directory:
/a/b/c/platform1/include/cTable/
/a/b/c/platform2/include/cTable/
/a/b/c/platform3/include/cTable/
So, what i want to do is to create next build variables (window->preferences->C++->build->build variables):
PLATFORMNAME_PLAT1 = "platform1"
PLATFORMNAME_PLAT2 = "platform2"
PLATFORMNAME_PLAT3 = "platform3"
PLATFORM_SELECTED = ${PLATFORMNAME_PLAT1}
INCLUDE_DIR = "/a/b/c/${PLATFORM_SELECTED}/include/"
Then, using the project properties, C++ general->paths and symbols->includes, add include directories that way:
${INCLUDE_DIR}/cTable
${INCLUDE_DIR}/cRow
${INCLUDE_DIR}/cComponentBase
${INCLUDE_DIR}/cTimers
That way, when changing the platform, i only have to edit the PLATFORM_SELECTED build variable, setting it to the PLATFORMNAME i want, even without remembering the platform directory name.
The problem is that the INCLUDE_DIR variable is not expanded and i have lot of errors like "invalid project path: include path not found (/a/b/c/include/cTable)". I think that the problem is the type of the build variables. INCLUDE_DIR has Path type, but i've tested using both path and string types for the other without any success. I would like to ask if someone can point me to a good approach for the creation of these build variables.
I dont use eclipse for compiling, but just for code editing, so what i want is to use the code completion and syntax highlighting.

Header file inside the same solution

http://youtu.be/6NCtnKcwOas (select better quality!)
As you can see on the attached video, I have the two projects in my solution - a dll creator and a simple testing project. Just followed this tutorial .
Why does the MathFuncsDll.h still remain undetected?Everything works fine after specifying the full path after '#include'. However, I don't want to use such rough-and-ready method because it looks messy and unprofessionally.
If you can specify the file using an absolute path, but not by only using its filename, the compiler doesn't "know" about the folder containing that file.
You can tell the compiler about your additional include directories via the /I directive (documentation). And of course you can set that via the IDE.