Solved

How do I compile programs with my Own Header files?

Posted on 1997-07-24
2
221 Views
Last Modified: 2012-06-27
I do I create a program which includes my own header file files? Do I create a project and then what?  I tried to create a new project (if thats what I am suppose to do), I make a header file time.h and include that into my time.cc file. My main.cc includes time.h, the program copiles ok but when I try to run it, it say unable to open c0wl.obj.  What gives??? help please. This is my first program to include header files of my own. :)
0
Comment
Question by:deeznutz
2 Comments
 

Accepted Solution

by:
LeChat earned 10 total points
ID: 1165839
Include files are definition files. In theses files, you put only functions _prototypes_.
The body of the functions go into libraries files or object files.
The file you have problem with (c0wl.obj) is the startup object file. Nearly every C program have a startup object file. It will be linked with your program at link time. I you don't link this file, you will not be able to run your program.

EXAMPLE
=======

main.cc
-------
  #include <stdio.h>
  #include "time.h"   // quote are to direct compiler to first
                      // look for you file in current directory

  void main(void)
  {
    printf("Current time is %02u:%02u:%02u",
           GetCurrentTime(HOUR),
           GetCurrentTime(MINUTE),
           GetCurrentTime(SECOND));
  }

time.cc
=======
#include "time.h"

int GetCurrentTime(int hms)
{
  switch(hms)
  {
    case HOUR:
      return 12;   // Put your own code here

    case MINUTE:
      return 42;   // Put your own code here

    default:
      return 17;   // Put your own code here
  }
}

time.h
======
#define HOUR    1
#define MINUTE  2
#define SECOND  3

extern int GetCurrentTime(int hms);


Output:

   Current time is 12:42:17


time.h exists to tell main.cc that the function GetCurrentTime exists and take one integer parameter and return an integer.
time.cc exists to implement GetCurrentTime body.
You must add main.cc AND time.cc to your project.

How this help you
0
 
LVL 1

Author Comment

by:deeznutz
ID: 1165840
I do add Time.cc and main.cc to my project, but you mentioned before that if I do not link the obj file c0wl.obj the program wont run... which I think is my problem, so how do Iink this file to make my program run??? Basically I need to know how to run my program, it compiles ok, but when I try to run it, I get that error messsage mentioned before.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now