Include path not expanding when using path variable - c++

I create a new c++ project. Then right click on the project -> properties -> Resources -> Linked resources, where I defined a path variable :
MY_PROJ_ROOT <some_correct_path>
Then I went to compiler options -> Include options, where I tried to add include path combined with the path variable like this :
"${MY_PROJ_ROOT}/include"
but the include directory is not shown in the Include tab under the project menu. Instead of showing full include path (like for other includes), I get only this : /include.
So, am I doing something wrong when using path variable to set include? What is the correct way?
PS I checked paths, and everything I could think of, but nothing worked.

Finally I figured out :
Open project properties -> C/C++ Build -> Build Variables tab, and add new variables :
MY_PROJ_ROOT <some_correct_path>
Then the variable is going to work for the includes tab.

Try ${env_var:MY_PROJ_ROOT}. Eclipse comes with its own schema for inserting variables. If there should be a button "Variables...", click it and you will see the various options, of which one is env_var that takes an environment variable name as argument. In fact, you may want to use ${project_loc} instead of defining your own variable.

Related

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

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.

On Eclipse, is there a way to modify several include paths in one shot?

I'm trying to change the include paths from relative path to fixed path. Is there a way to do it in a bulk? Or do I need to manually edit one by one?
I'm currently going to
C/C++ Build -> Settings -> ** Compiler -> Includes
And have to manually edit the path from something like:
../../../../../platform/hal/rtc
../../../../../platform/hal/sai
../../../../../platform/hal/sim
To
"C:\Freescale\KSDK_1.0.0/platform/hal/rtc"
"C:\Freescale\KSDK_1.0.0/platform/hal/sai"
"C:\Freescale\KSDK_1.0.0\platform\hal\sim\"
I wonder if there's a way to export this to an XML file or something and then import it.
Thank you!
I've had this issue before in a workspace that contains more than 40+ similar C++ projects. The way I deal with it is to write a shell script that modifies the .cproject files on disk:
Use find to recursively find the .cproject files that I need to modify.
Use sed to search and replace inside each file using sed s/find-expression/replace-expression/g < .cproject > .cproject.tmp.
When I'm happy that the .cproject.tmp files contain the correct replacements then I add mv .cproject.tmp .cproject to the script to finalise the operation.
Since you're using Windows you'll need to get your projects into an environment where shell-scripting is easy - cygwin or msys are both powerful enough to do this.
In C/C++ General -> Paths and Symbols -> Includes ... (then possibly your language), there is an export settings button which has a checkbox which includes the includes path. To import these settings into another project, you would use the import settings button when you open the properties to the same place in another project.

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.

Use source files in different directory in NetBeans Dynamic Library Project

I am new to C++ and NetBeans and I am trying to build a Dynamic Library project using it :). I want to build a plugin which uses source files located in different directories, and would like to keep them separately (as its a plugin ;)). I already tried to include the directory where the source files are located using Properties > Build > C++ Compiler > Include Directories, but it still gives errors in referencing to these files. These errors say the following:
"Cannot find include file "vtkPolyDataAlgorithm.h" "
Can anyone help me on this? I assume its a bit of a basic-basic-basic question, but I'm trying to learn autodidactically as a geologist from background, so you might see my problem :). I really hope you can help me out! Thanks :)
Ellen
While your way is the default way to add directories which contain additional headers (e.g. for libraries), you can add further Source-directories using Properties -> General -> Source Folders (-> Add).
It's also possible to add files (cpp / h) to your project, without setting a directory:
Right click on your project -> Add existing item ... or Add existing items from folders ...
But you have to care about your paths, you may have to browse to the headers using #include "../headers/here/example.h.

Cannot open include file "AIUtilities.h": No such file or directory. But it exists?

I have a two projects, AI and Core, which used to hold a circular dependency. I have a CoreUtilities file that I have broken up to remove this dependency, and added the functions I have removed to a new file called AIUtilities(.cpp/.h).
I then went to the piece in my AI project that uses these functions and added #include "AI/AIUtilities.h" and changed the function call from CoreUtilities::Functionname to AIUtilities::Functionname. Upon compile, I recieved the error given in the title.
Why! How can I fix it?
Did you update your project settings with the path to the direcory containing AI/AIUtilities?
Update:
From the solution explorer window, right click on your project and choose "properties" then a new windows "your_project_name property page" will pop up.
In this window on the left pane you'll see a tree. Click on 'Configuration properties' which expands to multiple choices. Continue clicking on 'C/C++' then on General. On the right pane appears multiple properties that affect your project.
Choose the "Additional include directories" property and add the path to your new directory. For instance if your path is : "C:\AI\AIUtilities.h" add the following: "C:\" in the property.
Click on "Aplpy button". Done.
As mentioned in other post, you must consider that moving your project around will break your project settings. Don't forget to update them. Or use either environnement variable to set the root of your project or use the "../../" trick. But personnaly I prefer the former.
You need to ensure that the parent directory of AI is on your header include path. Assuming that your code is laid out like this:
blah/source/
AI/
AIUtilities.h
AIUtilities.cpp
Core/
CoreUtilities.h
CoreUtilities.cpp
So either you need to have the header search path to '/blah/Source' or '..' depending on how your directories are structured.
Note that if you have sub-directories inside each project then this can cause problems with resolving the header search path. In that case set the header search path to $(ProjectDir)\.. .