Solved

How do I compile programs with my Own Header files?

Posted on 1997-07-24
2
223 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

856 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