Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-02-2011, 05:34 AM   #1
Registered: Mar 2006
Posts: 622

Rep: Reputation: 43
include ,h files from dir inside dir

Hi all,
hope this makes sense, it's hard to put into words.
Basically I have a dir that contains my makefile and another directory inside this called source this holds main source files. External to these I have a couple of dirs common and drives.

In my make file I use
DINCDIR = -I../Drivers -I../CommonFiles

to include the protoypes from the headers in the folders common and drivers used by source, this works fine. However in common and drivers I use a few variables that are set in the source dir. I set these with externs inside the common and driver files. However I'm sure I should be able to set the directory path for source inside my makefile. So say I have inside source hardware.h with prototypes, I set
DINCDIR = -I/Source -I../Drivers -I../CommonFiles

Then from a c file inside my common folder I say #include "hardware.h" the file should be able to see hardware.h and it's protoypes. However I get

error: Hardware_Config.h: No such file or directory
error: ‘Button_1’ was not declared in this scope

Is there some way I can get the extern dirs to see the source dir?

The set out is something like

level 1 common dir driver dir
level 2 main dir cointains makefile
level 3 source dir source files

Thanks in advance, this is simple to see but hard to put into word :s
Old 02-02-2011, 06:06 AM   #2
Senior Member
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,539

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Originally Posted by knobby67 View Post
... However in common and drivers I use a few variables that are set in the source dir. I set these with externs inside the common and driver files.
In a nutshell, you have a poor layout for your code.

If I understood you correctly, you have external components (drivers and common) that are "reaching" into your source code for access to global variables. It is normal for a project to reference external libraries (e.g. libc or your library), but for a library to depend on a project is blasphemous.

You need to consider re-factoring your code, rather than to come up with a hokey solution. I strongly suggest that you dispense with the global variables, and instead consider declaring local variables that can be passed as parameters to functions that you call. If a function needs the value of a variable, then it should call a "getter" function that provides the value. As for the rest of your code, it is hard to speculate what you have. But from what you posted, the common code does not seem so "common".

Last edited by dwhitney67; 02-02-2011 at 06:07 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
cp help, copying multiple doc files from multiple dir to one dir. How do i do that? w@m Linux - Newbie 5 02-03-2010 09:56 AM
Remove Certain Files/Dir from Large Dir thomas.beaver Linux - Newbie 2 01-27-2008 08:47 AM
Command to display /dir, /dir/sub, /dir/sub/files knockout_artist Linux - Newbie 9 10-25-2007 02:57 PM
Q. moving /bin dir files to /dev dir?? Texas_student Linux - Software 2 03-26-2006 11:42 PM
Include dir help gilinko Slackware 1 07-06-2002 07:03 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:29 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration