GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Jan-2007, 10:38
bobcory bobcory is offline
New Member
 
Join Date: May 2005
Posts: 6
bobcory is on a distinguished road
Angry

Linking to an Include File


I have just started using MS VC++ 6 after a long lay off and have one of those problems that are irritating because you know the answer is "obvious"

here is the problem. I am trying to run a demo program which uses a file something.h which I have a copy of

the code looks like
CPP / C++ / C Code:
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <windows.h>
#include <sys/timeb.h>
#include <time.h>
#include <something.h>
//etc etc

I am getting an error message:
"fatal error C1083: Cannot open include file: 'something.h': No such file or directory"

Obviously I need to register something.h or link to it or whatever. The question is HOW???
Last edited by LuciWiz : 29-Jan-2007 at 12:21. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 29-Jan-2007, 13:51
TurboPT's Avatar
TurboPT TurboPT is offline
Regular Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 924
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Linking to an Include File


Is 'something.h' a file of your own, in the project's directory?

If so, then you probably need to try:
CPP / C++ / C Code:
#include "something.h"
The < > typically resolve to a path of the header files that came with the environment. So, using < > to #include a file of your own will fail if it's not in that location.

See #include in the help for more information.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #3  
Old 29-Jan-2007, 16:57
bobcory bobcory is offline
New Member
 
Join Date: May 2005
Posts: 6
bobcory is on a distinguished road

Re: Linking to an Include File


Quote:
Originally Posted by TurboPT
The < > typically resolve to a path of the header files that came with the environment

This is somebody else's code and I am trying to understand it. Have now got it working but not sure why! When I leave the code as:

#include<something.h>

it appears to find it OK if it is in the directory where the code is but am not clear why as I have copied the whole lot across from the C: drive to my L: drive! I guess it just has a good sniff around in the same directory but that seems a little crude ....

There is some stuff here from good old microsoft:
http://support.microsoft.com/kb/85956

"The online help provides the following information about the #include preprocessor directive:
If the file is still not found or if the path-spec is enclosed in angle brackets, the next directories searched are the ones specified using the /I custom compiler option. After those have been searched, the compiler searches the directories specified in the INCLUDE environment variable.
This documentation is correct if the compiler is invoked from the command line. However, from within the Visual WorkBench, the INCLUDE environment variable is ignored. Instead, the directories searched are those set by choosing Directories from the Options menu in Visual C++ for Windows and in Visual C++ 32-bit edition versions 1.0 and 2.x, or by choosing the Directories Tab from the Options dialog box in Visual C++ version 4.x. This information also applies to the LIB environment variable.

To set the directories searched for include files in Visual C++ version 4.x, use the following steps:
1. Select Options... from the Tools menu.
2. Select the Directories tab in the Options dialog box.
3. Select the appropriate platform (e.g., Win32) in the Platform drop-down list box. The directories to be searched will be specific to this platform.
4. Select "Include files" in the Show directories for drop-down list box.
5. Enter the full paths of the directories to be searched in the Directories editable list box, one directory per line. The directories will be searched in the order listed.
6. Press OK to confirm the selections.
For more information on setting directories in Visual C++ version 4.x, search for "Setting Directories" in the Books Online. For more information on the #include preprocessor directive, search the online documentation for "#include"."
  #4  
Old 21-Feb-2007, 16:12
killzone killzone is offline
Junior Member
 
Join Date: Nov 2006
Posts: 66
killzone is an unknown quantity at this point

Re: Linking to an Include File


If the file something.h is a header file that you created in your project then to include it use :
CPP / C++ / C Code:
#include "something.h" 

if it is a standard header for c++ you have to use :
CPP / C++ / C Code:
#include <something.h>
//Such As
#include <iostream>
  #5  
Old 21-Feb-2007, 18:07
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,623
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Linking to an Include File


Quote:
Originally Posted by killzone
If the file something.h is a header file that you created in your project then to include it use :
CPP / C++ / C Code:
#include "something.h" 

if it is a standard header for c++ you have to use :
CPP / C++ / C Code:
#include <something.h>
//Such As
#include <iostream>

In fact, both the C standard and the C++ standard say that the paths searched for files indicated in #include <something> and also in #include "something" are implementation-defined. In other words one compiler vendor might write his preprocessor so that the <form> doesn't search the current directory but the "form" does. Or both or neither.

Many compilers follow the conventions suggested by the original author of the C language, as commented in K&R first and second editions. (See Footnote.)

"Any source line of the form
#include "filename"
or
#include <filename>
is replaced by the contents of the file filename. If the filename is quoted, searching for the file typically begins where the source program was found. If it is not found there, or if the name is enclosed in < and >, searching follows an implementation-defined rule to find the file."

Note that this is consistent with killzone's recommendation, except his words "have to" would have to be omitted for some compilers.


So: some compilers do it one way and some do it the other. I perceive that it's not very productive for me to try to guess (or argue) how someone else's compiler works. Even if I have one from the same source/vendor, installation details may cause different behavior from system to system.

In other words: Your Mileage May Vary. If one way doesn't work, try the other. If it's a project managed from the Visual C++ Integrated Development Environment, add it to your project (you may have to navigate to the right directory in the project files pane).

Regards,

Dave

Footnote: C Programmers in the 20th century knew what "K&R" meant: the book The C programming Language by Brian Kernighan and Dennis Ritchie. When the first edition was published (somewhere around 1978) there were no other books about C. UNIX had just been unleashed on the world, and much (most?) of UNIX was written in C.

The second edition of K&R was published in 1988, just about the time that the first C Standard was released, and has almost everything in the so-called C89 standard. The second edition of K&R is still in print, and is as good a language reference as the Standard. And it has many examples of uses of various C language features. (And the code in the book really works!!!!!)

Almost all serious C compilers comply with almost all of the language requirements spelled out in the C89 standard. That doesn't help with things specific to C++ (classes, operator overloading, function overloading, namespaces, etc.) but an awful lot of C++ is really C. (The original name of what we now call C++ was "C with Classes".)
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 07:44
fltk-2.0 cvs Plumb FLTK Forum 20 13-Nov-2004 07:10
help with classes bucho MS Visual C++ / MFC Forum 3 20-Oct-2004 06:16
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 10:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:27.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.