Solved

How do I compile programs with my Own Header files?

Posted on 1997-07-24
2
220 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

772 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

10 Experts available now in Live!

Get 1:1 Help Now