header file

M

mescaline

Hi I have the following doubt about header files --
I have the foll. 3 files in a folder.

File 1: one.cpp
#include <hel.h>
#include <iostream>
using namespace std;

int main(){
hello();
return 0;
}


File 2: hel.h
#ifndef HEL_H
#define
void hello();
#endif

File 3: hel.cpp
#include <hel.h>
void hello(){
cout << "Hello" << endl;
}

--------------
I just need the output Hello using this header file formatting. I have
these three files in a folder. How should I compile these three files
using g++? WHen I just try g++ one.cpp, I get the output: hel.h: No
such file or directory

Thanks
m
 
J

Jeff Schwab

mescaline said:
Hi I have the following doubt about header files --
I have the foll. 3 files in a folder.

File 1: one.cpp
#include <hel.h>
#include <iostream>
using namespace std;

int main(){
hello();
return 0;
}


File 2: hel.h
#ifndef HEL_H
#define
void hello();
#endif

File 3: hel.cpp
#include <hel.h>

Should be:

#include "hel.h"

The angle brackets (<>) tell the compiler to look in a set of standard
directories, not the local directory. Alternatively, since you're using
g++, check out the compiler's -I option.
 
C

Chris Mantoulidis

Hi I have the following doubt about header files --
I have the foll. 3 files in a folder.

File 1: one.cpp
#include <hel.h>

#include "hel.h"
#include <iostream>
using namespace std;

int main(){
hello();
return 0;
}


File 2: hel.h
#ifndef HEL_H
#define

it should be #define HEL_H
void hello();
#endif

File 3: hel.cpp
#include <hel.h>

#include "hel.h"
void hello(){
cout << "Hello" << endl;
}

--------------
I just need the output Hello using this header file formatting. I have
these three files in a folder. How should I compile these three files
using g++? WHen I just try g++ one.cpp, I get the output: hel.h: No
such file or directory

Thanks
m

Wrong way to compile them... Do:

g++ -c hel.cpp
g++ -c one.cpp
g++ -o one one.cpp

;) I suppose you are on Linux, that's why I add no extension to the
executable. You can change it if you want
 
R

Rolf Magnus

Chris said:
Wrong way to compile them... Do:

g++ -c hel.cpp
g++ -c one.cpp
g++ -o one one.cpp

Uhm, and do you think that will be better? ITYM for the last line:

g++ -o one one.o hel.o

For such small programs, however, it's simpler to do it all in one line:

g++ one.cpp hel.cpp -o one
 
M

mescaline

#include "hel.h"


it should be #define HEL_H


#include "hel.h"


Wrong way to compile them... Do:

g++ -c hel.cpp
g++ -c one.cpp
g++ -o one one.cpp

;) I suppose you are on Linux, that's why I add no extension to the
executable. You can change it if you want
Hi Thanks for your reply
But it still doesn't work your way. It spits:

hel.cpp:1: hel.h: No such file or directory

Please help

m
 
C

Chris Mantoulidis

Rolf Magnus said:
Uhm, and do you think that will be better? ITYM for the last line:

g++ -o one one.o hel.o

I did a bad typo ;) I was meaning to do that ---^
For such small programs, however, it's simpler to do it all in one line:

g++ one.cpp hel.cpp -o one

maybe
 
C

Chris Mantoulidis

Hi Thanks for your reply
But it still doesn't work your way. It spits:

hel.cpp:1: hel.h: No such file or directory\

Yo sure you've got them in the same directory? And you sure you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,413
Latest member
KeiraLight

Latest Threads

Top