Include '.h' and '.c' files in project from outside directory

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In my AS7 project I want to include '.h' file present in directory outside of project. I used relative path of the file to be included, in my main.c file but getting build error as "file not found". I want to avoid adding the source & header files to my project as copy or as link.

I came across this question "https://www.avrfreaks.net/forum/s..." but this is w.r.t. AS6. Is to possible to achieve this in AS7? Is creating library only solution for this?  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I suspect that this concept of having the program scattered around in separate files stems back to the 1960s, when computer editors could only hold files that had a few thousand characters at max.  It doesn't seem to make sense at the present when editors can hold hundreds of pages in their memory banks.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Browse for the external header files. Add the path to your include directories list.
This will be fine until you want to export your project to a colleague.
In which case, you really need to copy the files to your local project directory.
David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:
I suspect that this concept of having the program scattered around in separate files stems back to the 1960s, when computer editors could only hold files that had a few thousand characters at max.  It doesn't seem to make sense at the present when editors can hold hundreds of pages in their memory banks.
I don't get the connection.

 

In any case, it makes perfect sense to want every project to use the same copy of a file.

If the time comes to fix or improve it, the change is only required in one place.

 

The opposite can also make sense. Stability might be more important than possible maintenance.

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Adding relative or absolute path of header files is still giving "not found" error. Header and source files are outside of project directory. I want to avoid adding exisiting items as link.  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

karanInterdigital wrote:

Last Edited: Tue. Mar 15, 2016 - 07:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

karanInterdigital wrote:

 

karanInterdigital wrote:

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
Browse for the external header files. Add the path to your include directories list.

 

Adding relative or absolute path of header files is still giving "not found" error. Header and source files are outside of project directory. I want to avoid adding existing items as link.

 

*****************************************************************************************

 

Apologies for blank comments. Unable to delete those 

 

Last Edited: Tue. Mar 15, 2016 - 07:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Show your include statement.

You found the correct directory when Browsing.   If you add it to the Include directories list,  the Compiler will find it too.

 

I agree with skeeve.   You want a single instance of a file.    Otherwise you create a maintenance nightmare.

Using an absolute path or relative path makes no difference to your build.    If you export the project,   you need to add a copy that is local to the project.

The whole project gets exported.    This is fine if the header is never going to be edited.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
I agree with skeeve.   You want a single instance of a file.    Otherwise you create a maintenance nightmare.

Using an absolute path or relative path makes no difference to your build.    If you export the project,   you need to add a copy that is local to the project.

The whole project gets exported.    This is fine if the header is never going to be edited.

How to export depends on one's target audience.

In the case of someone who needs to get up and running ASAP, that is certainly the thing to do.

OTOH, if the included code is third party software maintained by someone else,

the thing to do might be to export both of them separately and give instructions as to how and why to link them.

The target audience might already have the third party software or might have a suitable substitute.

Then again, the technical expertise of the target audience might require the first option.

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
Show your include statement.

 

I am successfully able to include the directory containing '.h' files but I have to add the source ('.c') files as link to my project - this builds the project successfully without any errors. Actually I wanted to avoid adding '.c' files as link but I think I will have to add them. Anyways I checked the 'cproj' file created by AS7 and it contains include statements as relative path pf '.c' files as below, this addresses my concern. I just wanted to avoid any absolute paths in the link.  

 

<Compile Include="..\..\cCoap\coapPacket.c">
      <SubType>compile</SubType>
      <Link>src\coapPacket.c</Link>
    </Compile>
    <Compile Include="..\..\cCoap\coapProcessor.c">
      <SubType>compile</SubType>
      <Link>src\coapProcessor.c</Link>
    </Compile>

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you find yourself having to edit the XML you are not using the tool in the right way!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I do not have access to AS7 at the moment, but in other Visual Studio-based projects you have a means to define various directories. Point being, there should be a way to add multiple include file directories. This will allow you to store commonly used files in their own location and avoid duplication.

 

I'll look when I get home to see if I can find the dialog...

  • "Give me six hours to chop down a tree and I will spend the first four sharpening the axe."  -- Abraham Lincoln
  • "All right wise guy, where am I?"   -- Daffy Duck
  • "Well, we're safe for now. Thank goodness we're in a bowling alley."  -- Big Bob, Pleasantville
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I do that so I can have libraries that I can use in more than one program. Here's the thread where Clawson taught me how to do it: https://www.avrfreaks.net/forum/s...

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut.