Serving the Quantitative Finance Community

 
User avatar
player
Topic Author
Posts: 0
Joined: August 5th, 2002, 10:00 am

compiling in c++

August 1st, 2004, 4:15 pm

I'm currently builing header files and source files in c++ but when I want to add these to another project I'm getting a compile error c1083...basically saying the file does not exist...I know it exists and I've added the file in the usual way..ie right clicking in the solution explorer window in the source file and header file respectively and go to "add existing item" and the n selceting the corresponding header and source files...Anyone know what I'm doing wrong??
 
User avatar
daveangel
Posts: 5
Joined: October 20th, 2003, 4:05 pm

compiling in c++

August 1st, 2004, 5:22 pm

You dont need to add header files to the project just source files. What you need to do is to tell the compiler where to find the header files. In VC++ under the Tools, Options there is a directory tab. You can add the directory or folder where your header files are kept into the list.
Last edited by daveangel on July 31st, 2004, 10:00 pm, edited 1 time in total.
knowledge comes, wisdom lingers
 
User avatar
hmerkinger
Posts: 0
Joined: May 10th, 2004, 6:39 pm

compiling in c++

August 1st, 2004, 10:04 pm

daveangel is right, more specifically under VS 2003 go toTools-Options-ProjectsUnder C++ directories select "Show directories for include files" in the upper right hand corner.Then add your directory that contains the header files.I find it strange though that the compiler does not recognize your header file when you copy itto the project directory and add it to the project. You do not have to do this as explained bydaveangel, but nevertheless it should work that way. It has always worked for me.What is the version of VC++ you use?HTH,Hans-Marc
 
User avatar
Marine
Posts: 0
Joined: July 17th, 2003, 7:56 am

compiling in c++

August 2nd, 2004, 8:54 am

It's much cleaner to add all of these files (.h/.cpp, etc..) to the project. You are must likely doing something wrong. If for some reason that doesn't work, your second choice should be to add a special path to the include directory in the project setting. Only as a last resort should you add this path to the "Tools/Options/Directory" location. This really should be used for for common libraries which you are going to use in all of your apps. You could run into alot of problems if you are not careful.My $.02
 
User avatar
mj
Posts: 12
Joined: December 20th, 2001, 12:32 pm

compiling in c++

August 2nd, 2004, 9:15 am

adding header files to the project does not affect where the compiler looks for them when compiling source files. so either put them in the same folder as your source files and use #include "myfile.h"or set the compiler or project options to look in the directory where you've put them
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

compiling in c++

August 2nd, 2004, 10:13 am

You need an explicit reference to the header file in your .cpp , or in stdafx.hOne does not normally add library header files to a project because they don't change.However, if you are building your own, they will change, in which case you need to tell the environment that your code is dependant upon it, since you need to recompile for each change to a header file. MJ's advice is right, but I would add the caveat that you should never ever have two copies of the same header file.This can do really bad things to you, your health and wealth, and the ozone layer.Consider a classclass MyClass{ public: double, thing, otherthing, mything, something_else;};This is in one copy of a header file.Imagine that someone adds a field:class MyClass{ public: double, thing, otherthing, mything,something_else, athing;};If no reference is made to "athing", then both will happily compile in either project. Indeed, if you explicitly load particular header files by using "MyHeader" rather than <MyHeader> which searches a path you can compile the same executable with both.However, imagine that a DLL or .OBJ is compiled with one definition of MyClass, and is used by some code with the other definition.There's a good chance this code will work.For a while...At the very least you can fear memory leaks, where one piece of code frees up memory based upon a smaller definition.A more likely effect is that small lumps of memory will change values when you least expect them to.Whatever version of the class you use, the debugger will only have one, it will give misleading results, since it may be looking in the wrong place for things.If you use the browser functionality, it will typically be consistent with what the deugger believes. Thus you may assign to "athing" in one piece of code, and see it get there, but when you step through to a difference bit of code the value will magically change. This may happen in a simple statement like x=y, where neither x, nor y have anything to do with MyClass.That's if you're lucky...If you're unlucky it will occur in a really ugly line of code, or better still in a 3rd party library you don't trust, and will thus blame.Happens in reverse as well, you will assign to a member, and it will overwrite the memory that belongs to another variable. If you have a lot of arrays, then at some point one value in it will change. Will you spot this ? No.If you're writing multi threaded apps, then it will be hard to hunt this bug down. Of course you don't know it's this type of bug, so you have no idea where to start looking.You're looking for 8 bytes, somewhere in two billion that change, sometimes.Sorry to go on, but this is a real world problem my team fought. You don't want to go there.
 
User avatar
player
Topic Author
Posts: 0
Joined: August 5th, 2002, 10:00 am

compiling in c++

August 3rd, 2004, 7:42 am

thanks for your help..what I eventually did was include hte source file of the header file and then in the main source file wrote #include "c:\\........." and put the exact location of the header file there...Went to the tool options dierectory then and also noticed it was there too...This workedHowever, on my mates version of c++ MS 6 all he has to do is go to "add existing items" and click on the header files and source files which he want to add..and it will compile..On my version c++.net this does not work erro c1083 pops up
 
User avatar
daveangel
Posts: 5
Joined: October 20th, 2003, 4:05 pm

compiling in c++

August 3rd, 2004, 8:07 am

this might work but its not portable. you should not have hard wired paths in your files.
knowledge comes, wisdom lingers
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

compiling in c++

August 3rd, 2004, 12:16 pm

Dave is of course correct, and it is buying into exactly the sort of problem I gave earlier.A simple method is to get in the habit of putting all the header files you build in one directory.You can set the environment variables to point at this.It also means that if one day, you wonder "what is that class I did for FDM ?", you know where to look.Code reuse is good.