GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Jan-2005, 22:28
crq crq is offline
New Member
 
Join Date: Jan 2005
Posts: 15
crq is on a distinguished road

.o compile UNIX stuff ... help please!


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
  #2  
Old 28-Jan-2005, 06:30
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough
Quote:
Originally Posted by crq
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

Do you have to go to the object files (.o) and then link them seperately or are you just having a problem going from .c and .h to .exe? If it is the second choice (and g++ is set up correctly) you should be able to cd to the directory containing someprog.c that has the main() that is your test program (and includes array.h) and use the following:
Code:
g++ someprog.c -o myprogram.exe
This should build your objects and then go through the linking process leaving you with your executable. (note, you really don't need the .exe on your command line but it doesn't hurt.)

Post some code if your question was about the programming itself.

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #3  
Old 28-Jan-2005, 06:55
crq crq is offline
New Member
 
Join Date: Jan 2005
Posts: 15
crq is on a distinguished road
Quote:
Originally Posted by cable_guy_67
Do you have to go to the object files (.o) and then link them seperately or are you just having a problem going from .c and .h to .exe? If it is the second choice (and g++ is set up correctly) you should be able to cd to the directory containing someprog.c that has the main() that is your test program (and includes array.h) and use the following:

Mark


no, basically, i have a .h file that has a template class of method declarations and method definitions (since template classes aren't supposed to be .C). i wrote a test class Test.C that will make some template objects and test them. i just don't know what to type at the UNIX cursor to make the link together, compile, and work. i was thinking that we were supposed to make an object file from the .h template file (bc the prof. has us referencing one of his .o files that was created from a .h further down the line), but i guess you can't make an object file from a .h? even if that .h contains declarations and definitions like my template class .h file does?

thanks
crq
  #4  
Old 28-Jan-2005, 07:13
dexter dexter is offline
Junior Member
 
Join Date: Jul 2004
Location: Queensland, Australia
Posts: 39
dexter will become famous soon enough
'man g++' or 'g++ --help' might help you out a bit, but I can give you a basic idea...

In the case of a single file, say, main.cpp, you can have it compiled and have the executable file as whatever you want (in this case, we'll call it testexec).

g++ main.cpp -o testexec

If you're main.cpp is ok, just give you the executable, else you'll get your error messages...

Now, let's say you're using two source files and a header... for instance custArray.h, custArray.cpp, main.cpp.

In that case, you'll want to create object files (files that haven't been linked), then join them all together at the end... this takes a few steps...

g++ -c -O custArray.cpp
g++ -c -O main.cpp
g++ -O -o arrayTest custArray.o main.o

You end up after these steps with an executable called 'arrayTest'. That's the basics... if you need more info, the man pages have loads. Also, if you want to compile bigger groups of files easier, it may be better to:

A. Write a makefile to automate the process... (man pages for using make... and probably google for the makefile format)
B. Write a shell script.

Option A is probably the best, as once the makefile is written, you need only enter ./make in the folder your project is in (and the makefile, too ) to recompile the whole project... that, and it is far more portable than a shell script.

Hope that helped a bit... (I've just been banging my head on the keyboard with *NIX, too... )
  #5  
Old 28-Jan-2005, 07:23
crq crq is offline
New Member
 
Join Date: Jan 2005
Posts: 15
crq is on a distinguished road
no, i don't quite get it. i know about having a .h file and then the .C file that has the definitions of the declarations in .h ... and then using a test.C file on them.

in THIS case, i have a .h file that has EVERYTHING (it is a template class so it has to have everything in a .h, not a .C) and i have a Test.C that makes .h ojbects and tests them.

when i do this
g++ Test.C
it tells me this ...
Test.C:4:19: Array.h: No such file or directory
...and all the errors that follow that problem.

and i did the #include<Array.h> at the top of my Test.C file. also, Array.h and Test.C ARE in the same directory.

other than doing
g++ Test.C
i don't know what else to type at the cursor. i have scoured the web for a WEEK now. and the MAN pages are too techie for me. i just don't understand what i am missing.


thanks
crq

Quote:
Originally Posted by dexter
'man g++' or 'g++ --help' might help you out a bit, but I can give you a basic idea...

In the case of a single file, say, main.cpp, you can have it compiled and have the executable file as whatever you want (in this case, we'll call it testexec).

g++ main.cpp -o testexec

If you're main.cpp is ok, just give you the executable, else you'll get your error messages...

Now, let's say you're using two source files and a header... for instance custArray.h, custArray.cpp, main.cpp.

In that case, you'll want to create object files (files that haven't been linked), then join them all together at the end... this takes a few steps...

g++ -c -O custArray.cpp
g++ -c -O main.cpp
g++ -O -o arrayTest custArray.o main.o

You end up after these steps with an executable called 'arrayTest'. That's the basics... if you need more info, the man pages have loads. Also, if you want to compile bigger groups of files easier, it may be better to:

A. Write a makefile to automate the process... (man pages for using make... and probably google for the makefile format)
B. Write a shell script.

Option A is probably the best, as once the makefile is written, you need only enter ./make in the folder your project is in (and the makefile, too ) to recompile the whole project... that, and it is far more portable than a shell script.

Hope that helped a bit... (I've just been banging my head on the keyboard with *NIX, too... )
  #6  
Old 28-Jan-2005, 08:43
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,791
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by crq
when i do this
g++ Test.C
it tells me this ...
Test.C:4:19: Array.h: No such file or directory

and i did the #include<Array.h> at the top of my Test.C file. also, Array.h and Test.C ARE in the same directory.


The following tells the compiler to look at its special magical places for include files:

CPP / C++ / C Code:
#include <Array.h>

Current directory is not normally part of that search path.

The following tells the compiler to look in the current directory first, then, if it's not found there, go to the normal search path:

CPP / C++ / C Code:
#include "Array.h"

Change your #include to this, and try again with "g++ Test.C".

Regards,

Dave
 
 

Recent GIDBlogWriting a book by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't run any programs I compile, please help NotReallyHere C++ Forum 2 29-Dec-2004 16:57
Invasion of Spyware and other stuff sweetjeebus05 Computer Software Forum - Windows 3 11-Oct-2004 23:31
RE: Sessions stuff for a confused programmer Dagma20 MySQL / PHP Forum 1 19-Mar-2004 06:10
Which platform- NT or Unix? priyanka Web Hosting Forum 2 16-Feb-2004 08:54
Useful SSH / Unix commands JdS Web Hosting Forum 4 17-Jan-2003 16:20

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:07.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.