<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
  <title>Linux Format forums</title>
  <link>http://www.linuxformat.com/forums/index.php</link>
  <description>Help, discussion, magazine feedback and more</description>
  <language>english</language>
  <copyright>(c) Copyright Sun May 19, 2013 8:45 am by Linux Format forums</copyright>
  <managingEditor>webmaster@linuxformat.com</managingEditor>
  <webMaster>webmaster@linuxformat.com</webMaster>
  <pubDate>Sun May 19, 2013 8:45 am</pubDate>
  <lastBuildDate>Sun May 19, 2013 8:45 am</lastBuildDate>
  <docs>http://backend.userland.com/rss</docs>
  <generator>phpBB2 RSS Syndication Mod by Lucas</generator>
  <ttl>1</ttl>

  <image>
    <title>Linux Format forums</title>
    <url></url>
    <link>http://www.linuxformat.com/forums/</link>
    <description>Help, discussion, magazine feedback and more</description>
  </image>

                                      <item>
                                        <title>Re: Problems compiling with g++</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=15379#15379</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=133'&gt;jjmac&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Wed Jan 11, 2006 6:32 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      &amp;gt;&amp;gt;&lt;br /&gt;
I read a couple of places now that you have to use extern in the header that gets included everywhere and either put the actual declaration in another header or a source&lt;br /&gt;
&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Basically, the &quot;extern&quot; keywoer just tells the compiler that the type has been declared/defined in another unit, and thats were the assembeller for allocating memory for the variable will also be. &lt;br /&gt;
&lt;br /&gt;
cbuilder will, and has also used, the same construct. If you were to click on cbuildes &quot;new&quot; menu item, bringing up its' selection dialog and choose a blank &quot;.h&quot; template, it would generate the same type of thing. Probably something like &quot;H_NAME&quot;.&lt;br /&gt;
&lt;br /&gt;
Easy to solve with a header of extern declarations though. You need to include it in any unit that will be using a variable so that the compiler will trust that it actually exists (grin)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
jm</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=15379#15379</comments>
                                        <author>jjmac</author>
                                        <pubDate>Wed Jan 11, 2006 6:32 am</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=15379#15379</guid>
                                      </item>
                                      <item>
                                        <title>Re: Problems compiling with g++</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=15092#15092</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=5299'&gt;otrus&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Fri Jan 06, 2006 4:12 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      I read a couple of places now that you have to use extern in the header that gets included everywhere and either put the actual declaration in another header or a source (.c/.cc/.cpp etc.) file. I never even knew this was actually how the c/c++ languages worked before since stupid (or maby smart..?) MSVC and Dev-cpp took care of all that! I'll sue them for ruining my programming skills and causing me to use weeks of valuble worktime being frustrated over gcc.</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=15092#15092</comments>
                                        <author>otrus</author>
                                        <pubDate>Fri Jan 06, 2006 4:12 am</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=15092#15092</guid>
                                      </item>
                                      <item>
                                        <title>Re: Problems compiling with g++</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=14925#14925</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=133'&gt;jjmac&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Wed Jan 04, 2006 12:30 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Howdy,&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&lt;br /&gt;
This only applies to homemade headers. I use the usual&lt;br /&gt;
&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The construct is designed to prevent multiple definitions from system headers, that may well be included by &quot;other&quot; system headers ... depending on what your package, or what you are including.&lt;br /&gt;
&lt;br /&gt;
It sounds like the error is occurring at link time, as would occur, if your including the same header in each unit your compiling.&lt;br /&gt;
&lt;br /&gt;
Try including it in one unit only, such as the unit that your using as your &quot;main&quot; source file, the one containing the main function.&lt;br /&gt;
&lt;br /&gt;
Then i'd have another header full of &quot;extern&quot; declarations, as suggested above ... to let the linker know that a declaration exists for the types in one of the other objects. That you would include in every source unit that you intend to use a type in. Safe enough to include it everywhere. Except for the one that has the original inclusion in.&lt;br /&gt;
&lt;br /&gt;
If your just compiling a single home-rolled source file, then it wouldn't be a problem.&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&lt;br /&gt;
 g++ complains that it gets declared in every file that includes the header! Madness!&lt;br /&gt;
&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Not madness &lt;img src=&quot;images/smiles/icon_smile.gif&quot; alt=&quot;Smile&quot; border=&quot;0&quot; /&gt;, quite correct behaviour. And it does suggest your are actually including it it a number of files. So the result is to be expected.&lt;br /&gt;
&lt;br /&gt;
As stated though, if that same header was being included by a number of other headers that were being included in a single unit, then it would prevent its' multiple inclusion. As per its' purpose and extensive use by the system headers.&lt;br /&gt;
&lt;br /&gt;
It can be a pain though, i know &lt;img src=&quot;images/smiles/icon_rolleyes.gif&quot; alt=&quot;Rolling Eyes&quot; border=&quot;0&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
jm</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=14925#14925</comments>
                                        <author>jjmac</author>
                                        <pubDate>Wed Jan 04, 2006 12:30 am</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=14925#14925</guid>
                                      </item>
                                      <item>
                                        <title>Re: Problems compiling with g++</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=14913#14913</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=115'&gt;Gordon&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Tue Jan 03, 2006 8:23 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Is your global object/variable defined/declared inside or outside of the &lt;br /&gt;
&lt;br /&gt;
#ifndef __HEADER_H__&lt;br /&gt;
#define __HEADER_H__&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
If it's declared/defined outside of the above construct then that will explain the problem. If it's declared/defined inside then I'm not sure what the problem is.&lt;br /&gt;
&lt;br /&gt;
You may be better off defining your object/variable inside a regular c,c++ file and then using the&lt;br /&gt;
&lt;br /&gt;
extern&lt;br /&gt;
&lt;br /&gt;
keyword inside a header to declare the object/variable. More information can be found in&lt;br /&gt;
&lt;br /&gt;
The C++ Programming Language by Bjarne Stroustrup ISBN 0-201-53992-6</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=14913#14913</comments>
                                        <author>Gordon</author>
                                        <pubDate>Tue Jan 03, 2006 8:23 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=14913#14913</guid>
                                      </item>
                                      <item>
                                        <title>Re: Problems compiling with g++</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=14908#14908</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=252'&gt;M-Saunders&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Tue Jan 03, 2006 5:24 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Try Anjuta: &lt;a href=&quot;http://anjuta.sourceforge.net&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;http://anjuta.sourceforge.net&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
M</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=14908#14908</comments>
                                        <author>M-Saunders</author>
                                        <pubDate>Tue Jan 03, 2006 5:24 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=14908#14908</guid>
                                      </item>
                                      <item>
                                        <title>Re: Problems compiling with g++</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=14907#14907</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=5299'&gt;otrus&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Tue Jan 03, 2006 5:18 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Sorry, using Ubuntu and Gnome right now. Are there any alternatives for Gnome (or is there a way to use kdevelop under gnome?)</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=14907#14907</comments>
                                        <author>otrus</author>
                                        <pubDate>Tue Jan 03, 2006 5:18 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=14907#14907</guid>
                                      </item>
                                      <item>
                                        <title>Re: Problems compiling with g++</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=14817#14817</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=849'&gt;1slipperyfish&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Mon Jan 02, 2006 5:17 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      what distro are you using? as kdevelop is very much like devC++ etc if you aren't a command line jockey &lt;img src=&quot;images/smiles/icon_biggrin.gif&quot; alt=&quot;Very Happy&quot; border=&quot;0&quot; /&gt; &lt;br /&gt;
paul</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=14817#14817</comments>
                                        <author>1slipperyfish</author>
                                        <pubDate>Mon Jan 02, 2006 5:17 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=14817#14817</guid>
                                      </item>
                                      <item>
                                        <title>Problems compiling with g++</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=14780#14780</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=5299'&gt;otrus&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Mon Jan 02, 2006 1:53 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Being used to Windows style developement suites (like visual c++, or borland c++) I'm used to leaving most of the compiling details to the IDE. I'm also used to being able to build most of my code without problems using Borland c++ Builder command line tools. But g++ for some reason doesn't compile or preprocess my sourcefiles together (or whatever) and therefore I can't include the same headerfile in more than one sourcefile! This only applies to homemade headers. I use the usual&lt;br /&gt;
&lt;br /&gt;
#ifndef __HEADER_H__&lt;br /&gt;
#define __HEADER_H__&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
to prevent the code from being included more than once, and for the most part there's no problem. But if i declare a global object (or variable) in the header, say, a standard errorhandling object, g++ complains that it gets declared in every file that includes the header! Madness! I've tried both compiling all the files each time, with something like &lt;br /&gt;
&lt;br /&gt;
'g++ -o output file1.cpp file2.cpp'&lt;br /&gt;
&lt;br /&gt;
and using a MAKEFILE to compile and assemble each file to object, and then to link them together. Nothing works! I can't belive programmers in bigger projects have to compile or preprocess everything in some intricate manner to get to use normal fileinclusion, so I'm probably doing some stupid Windows error.&lt;br /&gt;
&lt;br /&gt;
(By the way, I'll be posting this same under programming to reach more eyes)</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=14780#14780</comments>
                                        <author>otrus</author>
                                        <pubDate>Mon Jan 02, 2006 1:53 am</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=14780#14780</guid>
                                      </item></channel></rss>