![]() |
|
#1
|
|||
|
|||
.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
|
||||
|
||||
|
Quote:
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:
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
|
|||
|
|||
|
Quote:
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
|
|||
|
|||
|
'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
|
|||
|
|||
|
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:
|
|
#6
|
|||
|
|||
|
Quote:
The following tells the compiler to look at its special magical places for include files: CPP / C++ / C Code:
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:
Change your #include to this, and try again with "g++ Test.C". Regards, Dave |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
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