LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Linking program in g++? (https://www.linuxquestions.org/questions/programming-9/linking-program-in-g-24321/)

Eits0 06-25-2002 04:24 PM

Linking program in g++?
 
OK, I have begun serious self-studying of C++, and I'm currently at day 4 in the book "Teach Yourself C++ Programming in 21 days". It is very, VERY good book in my opinion!!!

However, in day one, there was little confucing thing called "linking", which was explained like "Translated source code becomes .OBJ file, which then can be linked to working .exe file."

I use g++ to translate my code, and it has never created any .obj files which I should link. It just makes .exe, or what ever it's called in Linux(?).
Soooo, my question is: Should it make .obj file or is it just winblows feature?

After I have completed the book, prepare for difficult questions ;)

PS: You feel smart? What is value range (arvoalue) of unsigned long int :p

crabboy 06-25-2002 10:12 PM

You must be compiling and linking in a single step to avoid creating object (.o) files. When you start creating more complex projects that require makefiles to assist in building you will be creating object files prior to linking.

crabboy 06-25-2002 10:21 PM

btw: 32 bits - 4294967295

Eits0 06-26-2002 08:05 AM

Quote:

btw: 32 bits - 4294967295
That is the correct answer!!! :D

OK, so if I'm going to make complex program that has self created libraries(? .h ending files anyway) I must link them together.
And am I able to run those programs I have now translated in machines without Dev software???

thx

llama_meme 06-26-2002 09:37 AM

No, multiple .h files will not require you to link multiple .o files. You will only have to link multiple .o files if you write multiple .c files. It's at this stage that make (man make) becomes useful. Until you start writing serious (useful) programs I wouldn't recommend worrying too much about this, just keep your source in one file.

Not quite sure if I understand your second question, but the executable produced will not require gcc to run, if that's what you mean.

Alex

Mara 06-26-2002 12:33 PM

To answer the second question: yes. If you have uses static linking (the default one), the answer is yes.

Eits0 06-27-2002 08:02 AM

OK, thankyou.
Now I feel bit wiser again.


All times are GMT -5. The time now is 08:51 AM.