473,594 Members | 2,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Header file compilation

Header file compilation

I'm coding a small irc bot, and I've noticed that compilation takes very
long when I add certain header files (compared to compilation time without).

I've tried to find out if it is possible to compile a header file, yet I
have only found that it is possible, but not how it is done.

I have RTFM, STFW and searched USENET, yet I have only found a document
saying "just write `g++ file.h`, and it'll work".

Thanks in advance
Mikael S. Hoilund
Jan 12 '06 #1
5 5850
Mikael S. H. wrote:
Header file compilation

I'm coding a small irc bot, and I've noticed that compilation takes very
long when I add certain header files (compared to compilation time
without).

I've tried to find out if it is possible to compile a header file, yet I
have only found that it is possible, but not how it is done.

I have RTFM, STFW and searched USENET, yet I have only found a document
saying "just write `g++ file.h`, and it'll work".


The only meaningful way to "compile" a header is to have a small source
file that consists of a single preprocessor instruction:

#include <yourheader>

or

#include "yourheader "

(don't forget to end the line with the newline character). Then you
compile that source file.

V
Jan 12 '06 #2
Mikael S. H. wrote:
Header file compilation

I'm coding a small irc bot, and I've noticed that compilation takes very
long when I add certain header files (compared to compilation time without).

I've tried to find out if it is possible to compile a header file, yet I
have only found that it is possible, but not how it is done.

I have RTFM, STFW and searched USENET, yet I have only found a document
saying "just write `g++ file.h`, and it'll work".

Thanks in advance
Mikael S. Hoilund


Header files (.h, .hpp, etc.) are quite litterally *included* in the
source file in which they are #included (headers, or .cc, .cpp, etc.).
You don't compile them separately because they are intended to share
information (types, constants, global variables, function prototypes,
class definitions, templates, etc.) needed across source files and
shouldn't have any useful compiler output by themselves.

So, if you don't need the information in that header file, then don't
include it. If you do, then you can deal with the long compile times or
try to reduce amount of information pulled in (e.g., if your header
includes ten others, but you only need one of those, just include that
one header).

Or you can be more specific by showing us some code.

Cheers! --M

Jan 12 '06 #3

Mikael S. H. wrote:
Header file compilation

I'm coding a small irc bot, and I've noticed that compilation takes very
long when I add certain header files (compared to compilation time without).

I've tried to find out if it is possible to compile a header file, yet I
have only found that it is possible, but not how it is done.

I have RTFM, STFW and searched USENET, yet I have only found a document
saying "just write `g++ file.h`, and it'll work".


This is an implementation-specific question. Many compilers include a
pre-compiled header option. gcc, for example, lets you pre-compile a
header file in exactly the way you describe. Other implementations , if
they offer pre-compiled headers, may do so in a different way. If you
are in fact using gcc, consult the gcc manual, which has a section on
pre-compiled headers:

http://gcc.gnu.org/onlinedocs/gcc-4....mpiled-Headers

Best regards,

Tom

Jan 12 '06 #4
Thomas Tutone wrote:
Mikael S. H. wrote:

I've tried to find out if it is possible to compile a header file, yet I
have only found that it is possible, but not how it is done.


This is an implementation-specific question. Many compilers include a
pre-compiled header option. gcc, for example, lets you pre-compile a
header file in exactly the way you describe. Other implementations , if
they offer pre-compiled headers, may do so in a different way. If you
are in fact using gcc, consult the gcc manual, which has a section on
pre-compiled headers:

http://gcc.gnu.org/onlinedocs/gcc-4....mpiled-Headers


Hm, I think that was exactly the document I stumbled upon. However, I
seem to be unable to put those instructions into practice. When I try to
compile it without -x, it says "compilatio n of header file requested".
When I try it with -x, it says "undefined reference to main".

And I'm sorry about the off topic post, but apparently my ISP is linux
hostile, since I can't get to a single linux related newsgroup.

Thanks
Mikael S. Hoilund
Jan 12 '06 #5
Mikael S. H. wrote:
Thomas Tutone wrote:
Mikael S. H. wrote:

I've tried to find out if it is possible to compile a header file, yet I
have only found that it is possible, but not how it is done.

This is an implementation-specific question. Many compilers include a
pre-compiled header option. gcc, for example, lets you pre-compile a
header file in exactly the way you describe. Other implementations , if
they offer pre-compiled headers, may do so in a different way. If you
are in fact using gcc, consult the gcc manual, which has a section on
pre-compiled headers:

http://gcc.gnu.org/onlinedocs/gcc-4....mpiled-Headers

Hm, I think that was exactly the document I stumbled upon. However, I
seem to be unable to put those instructions into practice. When I try to
compile it without -x, it says "compilatio n of header file requested".
When I try it with -x, it says "undefined reference to main".


Add -c (to compile only, no link).
And I'm sorry about the off topic post, but apparently my ISP is linux
hostile, since I can't get to a single linux related newsgroup.


Use Google Groups.

V
Jan 12 '06 #6

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

Similar topics

3
2217
by: Chris Mantoulidis | last post by:
Seperate compilation (that's what it's called, right?) seems to be quite popular, so I decided to get some info about it, and (d'oh) use it... But it's whole structure seems weird to me... Here's what I think of how it is (from what I've read): THE PROJECT +1st header file
16
12519
by: matthurne | last post by:
I just started learning C++ on my own...I'm using Accelerated C++. Something it hasn't explained and I keep wondering about is how header files actually work. I suspect it doesn't get into it because it is, as the authors love to say, "implementation specific". If that's the case, how does the compiler commonly handle them? I use Linux and gcc specifically. Basically, I don't understand how a header file being included makes a...
12
12860
by: blueblueblue2005 | last post by:
Hi, here is an example I copied from Deitel C++ book. but when I compile it, always get the above compilation error, no matter how I change the include order, please help. here is the files: Note: this is to practice Proxy classes. // Implementation.h class Implementation {
2
3689
by: Annie | last post by:
hello guys, I have a header file in the form of user control (.ascx) that all my pages inherit from it. I have a textbox that i need to access it from all the pages actually i show there user details there and needs to update it. So i set this textbox as Public and Static. The code compiles fine and the textbox is accessable to all pages however i have the following compilation errr: Compiler Error Message: CS0176: Static member...
8
3042
by: nrhayyal | last post by:
Hi c++ Gurus, Need your blessing. while testing few aspects with respect to header file inclusions, i observed few things which i would like to share with you. i have a file sqlca.h in which a structure sqlca is declared. i included this file as a soft link in /usr/include. the soft link is as follows: sqlca.h -> /usr/opt/db2_08_01/include64/sqlca.h
11
1870
by: mdh | last post by:
Well, K& R has finally gotten to header files!!! May I ask this. (Have checked out the FAQ) I am using "Xcode" to compile the program, so it may well be that this is doing something strange. What is unique to a header file? For example, if I define an integer thus:
8
7622
by: nishit.gupta | last post by:
I was having a problem with template class memer function definition , so i serched the net and find that template class member fuction definition should be in header file else compilation will be successful but not linking. Can somebody help me in telling the exact reason why compiler cannot find the reference of template class member function definition defined in cpp file?? following problem is not linking (undefined reference of...
4
6004
by: Madhur | last post by:
I have problems faced in adding definitions in the command header file. I have defined a header file which includes huge set of global constants and I am using them in all the C files. For example my sample.h file looks like this /************* File : sample.h
6
3429
by: bobby | last post by:
hi group, Does the header file size or number in include(s) effect the size of executable file? In other world if i chose a large header file and include it with my source file does it increase the size of the executable outcome at the end? thanks
0
7874
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8246
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8368
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8231
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5738
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1476
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1205
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.