STILL trying to figure out how to link files in C++ in a UNIX environment!! i just don't get it. how do i make .o files? what are they for? how do you "link" them with other stuff and "run" them. all i am capable of is g++ somepgm.C
and then a.out

sorrry .... frustrated. prof and TA just ASSUME that i know this ... and i don't.

i have a template class Arrray.h. i need to make a Test.C class that will have main() and make some Array<T> objects and test them. can ANYONE tell me the commands to do this?

thanks
crq

Hello,

In my day, we made something called a "makefile" in order to bind it all together. Do a search on makefiles.... I have not built one in quite some time.

I also believe that when the compiler makes the first pass, and sees the .h file referenced, it simply adds that file's text to the main program. I don't think it makes it into a .o and then links them things together. I thought that the compiler command simply hauled the text into a compiler, and then let the dogs loose.

Do not quote me; it has been some time since school.

Christian

headerfiles are not compiled, clear and simple.

.o files are compiled compilation units which have not yet been linked, header files are not compilation units.

yes. that makes sense to me. yet, my prof wants us to use one of his already compiled files (a .o file) that was made from a .h file. so that's why i was wondering if I needed to do the same.

thanks
crq

headerfiles are not compiled, clear and simple.

.o files are compiled compilation units which have not yet been linked, header files are not compilation units.

headerfiles are not compiled, clear and simple.

.o files are compiled compilation units which have not yet been linked, header files are not compilation units.

That's my understanding too, but a couple of weeks ago I asked a question in this forum about a header file like this:

// header file
#ifndef NUMBERS.H
#define NUMBERS.H

// Some typical header file stuff

#endif

My question was what are the first two lines about. I was told that their purpose was to avoid mutiple compilations. But header files are not compiled!

I should be asking the person who posted the answer to my question, but I don't remeber who that was or what thread it was on. Perhaps you can answer it.

By the way, the header files that come with my compiler, bcc32, have a lot of these "#ifndefine" statements.

My question was what are the first two lines about. I was told that their purpose was to avoid mutiple compilations.

Perhaps you remember it wrong -- was it to "[post=81677]prevent multiple inclusion[/post]"?

Header files aren't compiled but when the compiler sees
#include "filehere.h" ,
it looks for the file for that name in the directories specified. Then it looks through the header during runtime for what you need your code. So #ifndef is a if not defined then #define the file so the compiler knows its right. At least thats how i understand it.

Oh and to answer the question of multiple compilations... it only defines the file name if it wasnt defined.

Perhaps you remember it wrong -- was it to "[post=81677]prevent multiple inclusion[/post]"?

Yes, I can see how preventing multiple inclusions would work. (I do think the previous respondant said "multiple compilations", but that's not important) Thank you.

While I'm taking advantage of your knowledge, could yu tell me what a "pragma" is?

Yes, I can see how preventing multiple inclusions would work. (I do think the previous respondant said "multiple compilations", but that's not important) Thank you.

Uh, follow the link. The "previous respondant" was me, and no I did not say "multiple compilations".

It prevents multiple inclusion of the header.

While I'm taking advantage of your knowledge, could yu tell me what a "pragma" is?

A preprocessing directive which causes the implementation to behave in an implementation-defined manner. The behavior might cause translation to fail or cause the translator or the resulting program to behave in a non-conforming manner. Any such pragma that is not recognized by the implementation is ignored.

This article has been dead for over six months. Start a new discussion instead.