LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-16-2015, 04:12 PM   #1
shjz
LQ Newbie
 
Registered: Jan 2015
Posts: 2

Rep: Reputation: Disabled
Why am I not seeing any .o files after compiling a C++ program


I am compiling using:

c++ -o myexec main.cpp file1.cpp file2.cpp

however, I only obtain an executable (myexec) without seeing any .o files after "ls -al". This is my first exposure to Unix, I would highly appreciate an answer to my question.
 
Old 01-16-2015, 04:34 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
you might want to read a few guides
or better yet books

http://phoxis.org/2009/12/01/beginners-guide-to-gcc/

http://www.amazon.com/The-Definitive.../dp/1590595858

or

is it you need C and C++ guides
http://www.cprogramming.com/

but if you WANT objects
http://blog.teamtreehouse.com/the-be...-and-variables
 
Old 01-16-2015, 11:02 PM   #3
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Quote:
c++ -o myexec main.cpp file1.cpp file2.cpp
To get object files you have to do:

Code:
c++ -c main.cpp
c++ -c file1.cpp
c++ -c file2.cpp
c++ -o myexec main.o file1.o file2.o

Last edited by veerain; 01-16-2015 at 11:03 PM.
 
1 members found this post helpful.
Old 01-18-2015, 05:58 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
To add a bit to what the others said -

The "-o" only asks for an executable output, all other files created are discarded.

You should have "myexec" (assuming no compile errors happened) and that is your program to run.
 
1 members found this post helpful.
Old 01-19-2015, 08:10 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Indeed, the compiler is trying its best to do you a favor. You told it that you don't care about all those "extra" files; that you want your room to always be neat and tidy. So, it's helpfully throwing away those files for you, just like you asked it to do.
 
1 members found this post helpful.
Old 01-19-2015, 09:24 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
I would say read the man page, but there are a lot of info. So -c means to create .o files, without -c you will have no .o files. c++ works in several steps, and the final result is usually an executable (or libraries), not the intermediate .o files.
 
1 members found this post helpful.
Old 01-19-2015, 03:55 PM   #7
shjz
LQ Newbie
 
Registered: Jan 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you all for helping me. I understand why now. Thanks again!
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C program: i am getting errors when compiling this simple program batman4 Programming 8 12-11-2012 08:23 AM
[SOLVED] compiling a C program with header files in a separate directory emaritza Linux - Newbie 6 06-12-2012 05:47 PM
[SOLVED] Compiling A 'C' Program swamprat Programming 13 04-13-2011 07:09 PM
Compiling C program Udhayakrishnan Programming 8 02-10-2010 08:21 AM
Compiling a program lintho Linux - Software 2 08-24-2004 07:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration