473,387 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

#include from a subdirectory

How do I include headers which are in a sub directory (not in my main
src dir)?
I use a scripting language - Lua - to extend my C app and all the Lua
code is in the subdirectory \lua. I want to include the lua.h header in
one of my main source files but

#include ".\lua\lua.h"

doesn't work...

I've just tried it on Windows but the app is supposed to be portable to
Linux so there's also the "/" vs "\" issue..

copx
Nov 14 '05 #1
5 14780
copx wrote:
How do I include headers which are in a sub directory (not in my main
src dir)?
I use a scripting language - Lua - to extend my C app and all the Lua
code is in the subdirectory \lua. I want to include the lua.h header in
one of my main source files but

#include ".\lua\lua.h"

doesn't work...
As a matter of coding style you would put that in the makefile
and pass as arguments to the search directories of your compiler.
Your code might look as -

#include "lua.h"

..
..

And you might pass the include directories to the compiler.
say, if you are using gcc - it might be -
gcc -I ./lua yourprog.c

This syntax entirely depends on the implementation and the platform.
Refer to the manual to know this.

I've just tried it on Windows but the app is supposed to be portable to
Linux so there's also the "/" vs "\" issue..


As a convention, if you are writing portable apps, you have a separate
makefile specific to each implementation in which you specify all these
things. Of course, you can also tools like Ant, but i have seen people
using for java programs and not many people use Ant for building C
programs.

HTH.

--
Karthik.
Nov 14 '05 #2
#include "lua/lua.h"

.... for both Linux and Windows. Keep in mind the '\' indicates an escape
sequence (think '\n', '\r', '\0' and so on).

copx wrote:
How do I include headers which are in a sub directory (not in my main
src dir)?
I use a scripting language - Lua - to extend my C app and all the Lua
code is in the subdirectory \lua. I want to include the lua.h header in
one of my main source files but

#include ".\lua\lua.h"

doesn't work...

I've just tried it on Windows but the app is supposed to be portable to
Linux so there's also the "/" vs "\" issue..

copx


--
Remove '.nospam' from e-mail address to reply by e-mail
Nov 14 '05 #3
Try this option:'/I' when compiling.

copx <in*****@invalid.com> writes:
How do I include headers which are in a sub directory (not in my main
src dir)?
I use a scripting language - Lua - to extend my C app and all the Lua
code is in the subdirectory \lua. I want to include the lua.h header
in one of my main source files but

#include ".\lua\lua.h"

doesn't work...

I've just tried it on Windows but the app is supposed to be portable
to Linux so there's also the "/" vs "\" issue..

copx

Nov 14 '05 #4
James McIninch <ja*******************@comcast.net> writes:
#include "lua/lua.h"

... for both Linux and Windows. Keep in mind the '\' indicates an escape
sequence (think '\n', '\r', '\0' and so on).


Please don't top-post. Your response goes below the quoted text.

The '\' doesn't necessarily indicate an escape sequence in a header
name. Even though it's delimited by '"' characters, the stuff
following the "#include" is not actually a string literal token.

C99 6.4.7 says that if a '\' character occurs between the "" or <>
delimiters in an include directive, the behavior is undefined (though
an implementation is free to define the behavior if it chooses to do
so).

Consult the documentation for your compiler.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
copx wrote:
How do I include headers which are in a sub directory (not in my main
src dir)?
I use a scripting language - Lua - to extend my C app and all the Lua
code is in the subdirectory \lua. I want to include the lua.h header in
one of my main source files but

#include ".\lua\lua.h"

doesn't work...

I've just tried it on Windows but the app is supposed to be portable to
Linux so there's also the "/" vs "\" issue..

copx


#include "lua/lua.h"

MSDOS (not command.com) since 3.0 and all versions of Windows know
how to treat '/' in a file specification.

--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rob Long | last post by:
Hey, I've written a custom HTML library using many PHP scripts as seperate files (just like I'd do a java project) and I'm having some problems where I'm including scripts in different...
43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
0
by: Mart Rogers | last post by:
I have an asp.net project which includes some javascript files which live in a subdirectory to the project root directory. The include statements obviously expect the files to be in that...
2
by: Greg | last post by:
I'm new to html and web coding, this is a simple one - appreciate your help! I'm attempting to get my browser bar links to reside in a single .asp file to avoid multiple additions to pages when...
13
by: Bryan Harrington | last post by:
Hello all.. I'm working on an application that I'd like to use some shared files. Right now my directory structure is: / (root) .../Shared/ .../Reports/ .../Tools/
4
by: Bill | last post by:
Will IIS6.0 recognize a global.asa file located in a subdirectory on the webserver? I'd like a file that will execute whenever a file in the subdirectory is browsed - or, at least it is...
1
by: Alex VanderWoude | last post by:
I am trying to <include> some text into an XML documentation topic, but that text is stored in a file that is in a different directory than the "current" XML file. Using a relative path does not...
2
by: WisTex | last post by:
I've come across a very weird problem. Virtual includes work on all my ASP pages on the entire website, including those in subdirectories, yet they won't work on a particular page I created, even...
0
by: =?Utf-8?B?Qm9ubmll?= | last post by:
I have a basic ASP / Index Server search page. I have a web site contained in a subdirectory in the root of a main web site. What I’m trying to do is force the search page in the subdirectory,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.