Solved

How do I compile programs with my Own Header files?

Posted on 1997-07-24
2
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

739 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