This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I am linking a file.c and a file.h from another project. The file.c "includes" a main.h file. The main.h file in my local project defines a constant CONST. However, the project where the two linked files reside also has a main.h, which does NOT define CONST.
When I compile my local project I get a compile error in the linked file in the project where the linked files reside saying that CONST is undefined. It appears that the linked files are not referencing my local main.h file when they search for CONST.
Is this working properly, or is this a bug? I assumed that any linked file only brought in the text from the file and the search directory for the text (#include) in the linked file would be the current project directory. This does not appear to be what is happening....??
Thx,
MikeH
MikeH,
MikeH said:
Is this working properly, or is this a bug? I assumed that any linked file only brought in the text from the file and the search directory for the text (#include) in the linked file would be the current project directory. This does not appear to be what is happening....??
This is expected. Since the linked file stays in its original location everything is relative to the original directory. Therefore the #include preprocessor directive will behave in two different ways depending on how you define it:
- If you are using double quotes with the #include directive it will search first in the directory where the file is located and then in the include search path (option --include_path in the compiler options).
- If you are using <> in the #include directive, the compiler will search only in the include search path. In this case you can add the project directory to the include search path, thus allowing using individual include files per project.
Check the reference below for details about the #include preprocessor directive.
http://www.cplusplus.com/doc/tutorial/preprocessor/
Hope this helps,
Rafael
Rafael,
Thanks for reminding me of stuff that I had forgotten.
For the benefit of others:
Source file inclusion (#include)
This directive has also been used assiduously in other sections of this tutorial. When the preprocessor finds an #include directive it replaces it by the entire content of the specified file. There are two ways to specify a file to be included:
1. #include "file"
2. #include <file>
The only difference between both expressions is the places (directories) where the compiler is going to look for the file. In the first case where the file name is specified between double-quotes, the file is searched first in the same directory that includes the file containing the directive. In case that it is not there, the compiler searches the file in the default directories where it is configured to look for the standard header files.
If the file name is enclosed between angle-brackets <> the file is searched directly where the compiler is configured to look for the standard header files. Therefore, standard header files are usually included in angle-brackets, while other specific header files are included using quotes.
Thx,
MikeH
Rafael,
This is still not working for me. I am working on an OMAP-L138 project and want to keep a set of "common" files that are used both by the ARM and DSP. The common files reside in a folder within the ARM project (ARM/common). From the DSP project, which is in the same workspace as the ARM project, I link several common files into the DSP project. Each of these files references "main.h" file in the DSP project. But the main.h file for the DSP is in the DSP project folder.
However, I am getting compile errors when trying to compile the DSP project that say the "common" files cannot find their respective "main.h" file. Per your guidance above, each of the common files includes a reference to <main.h> (brackets, not quotes) , which resides in the DSP project root. This should tell the compiler to search for the main.h file in the include path, which I have configured to include the DSP project directory.
Can you verify that ccs will indeed search for an #include file that is included in a linked file but resides in the local project directory?
Thx,
MikeH
Mike,
Can you send the the console output of both ARM and DSP projects? That would help me get a better idea on what may be happening...
Cheers,
Rafael