Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Compiler Directives

Status
Not open for further replies.

abombss

Programmer
Apr 13, 2000
51
0
0
US
I am trying build my project, and I am getting linking errors.&nbsp;&nbsp;The problem is with my compiler directives and include files.&nbsp;&nbsp;Here are the headers for my project.<br><br>// assign10.cpp<br>#include &lt;fstream&gt;<br>#include &lt;iostream&gt;<br>#include &lt;string&gt;<br>#include &quot;classdef.cpp&quot;<br>using namespace std;<br><br>//classdef.h<br>#pragma once<br>#include &lt;fstream&gt;<br>#include &lt;iostream&gt;<br>#include &lt;string&gt;<br>using namespace std;<br>//CODE FOR CLASS DEFINITIONS<br>#include &quot;classdef.cpp&quot;<br><br>//classdef.cpp<br>#ifndef _CLASSDEF_<br>#define _CLASSDEF_<br>//CODE FOR CLASS IMPLMENTATION<br>#endif<br><br>I have tried numerous of other combinations and nothing seems to work.&nbsp;&nbsp;Every time the things in the classdef.cpp get redefined.&nbsp;&nbsp;If any could help let please let me know.<br>
 
To prevent multiple inclusion or redefintion of variables from a header file. Just do like<br><br>In the header file ,put this kind of code:<br><br>#ifndef SSINGH<br>#define SSINGH<br><br>// WRITE YOUR WHOLE HEADER FILE'S CONTENT.......<br><br>..............<br>...........<br><br>#endif.<br><br>This should be your header file's content , which will prevent&nbsp;&nbsp;redefinition of the variables.<br><br>Does it solve your problem?<br>Thanx<br>Siddhartha Singh<br><A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A><br><br>
 
also get rid of this line<br>#include &quot;classdef.cpp&quot;.<br>you should never include a source file<br><br>//ex HEADER FILE<br>&nbsp;#ifndef _HEADER_NAME<br>&nbsp;#define _HEADER_NAME<br>&nbsp;put includes here...<br><br>&nbsp;#endif<br><br><br>//SOURCE FILE<br>#include &quot;headerFile.h&quot;<br>put source here...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top