Solved

How do I compile programs with my Own Header files?

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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

632 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