LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-02-2012, 03:50 AM   #1
meet10may
LQ Newbie
 
Registered: Aug 2011
Posts: 9

Rep: Reputation: Disabled
cpp compilation in gcc


Hi,
I am trying to learn how to place classes in separate files.My main code is :
#include <iostream>
#include "Burrito.h"
using namespace std;

int main()
{
Burrito bo;

return 0;
}

My Burrito header file is :
#ifndef BURRITO_H
#define BURRITO_H


class Burrito
{
public:
Burrito();
protected:
private:
};

#endif // BURRITO_H

My Burrito Class is:

#include "Burrito.h"
#include <iostream>

using namespace std;
Burrito::Burrito()
{
cout<<"Tanmay Nath NBRC"<<endl;

}
I am using Ubuntu and I need to compile my main.cpp .I am using gcc main.cpp..Unfortunately it is giving me following errors:
/tmp/cc66TksP.o: In function `main':
main.cpp.text+0x10): undefined reference to `Burrito::Burrito()'
/tmp/cc66TksP.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp.text+0x3e): undefined reference to `std::ios_base::Init::Init()'
main.cpp.text+0x43): undefined reference to `std::ios_base::Init::~Init()'
/tmp/cc66TksP.o.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status


Please provide me the steps to compile it in correct manner.
Thanks
 
Old 01-02-2012, 05:42 AM   #2
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,254

Rep: Reputation: 314Reputation: 314Reputation: 314Reputation: 314
You need to compile this second file Burrito.cpp also, like that:
Code:
g++ main.cpp Burrito.cpp
Please use a CODE tags around your code for better readability.

Last edited by eSelix; 01-02-2012 at 05:43 AM.
 
1 members found this post helpful.
Old 01-02-2012, 06:27 AM   #3
meet10may
LQ Newbie
 
Registered: Aug 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thanks it worked..I did not try g++, rather i was trying gcc main.cpp Burrito.cpp.This did not work.In brief can you explain why did gcc not work and g++ work?
Thanks
 
Old 01-02-2012, 06:28 AM   #4
jkirchner
Member
 
Registered: Apr 2007
Location: West Virginia
Posts: 764

Rep: Reputation: 196Reputation: 196
I believe because it is C++ you wrote and not C
 
1 members found this post helpful.
Old 01-02-2012, 06:30 AM   #5
meet10may
LQ Newbie
 
Registered: Aug 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
thnx..
 
Old 01-02-2012, 07:25 AM   #6
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,254

Rep: Reputation: 314Reputation: 314Reputation: 314Reputation: 314
The gcc can compile C++ programs too (it detects it by .cpp file extension) but you also need a C++ library to link, which is done automatically by g++ and not by gcc.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
gcc (GCC) 4.3.2 20081105 (Red Hat 4.3.2-7) compilation error adhesh_19 Red Hat 0 01-05-2010 06:34 AM
have gcc compilation error during gcc installtion in linuxfromscratch vbshanmugaprakash Linux - General 3 12-13-2006 06:52 AM
cpp compilation error cranium2004 Programming 8 03-16-2006 08:39 AM
Now I have gcc/cpp/cpp, but still can't install sfingerh Linux - Software 2 07-30-2002 04:13 AM


All times are GMT -5. The time now is 02:18 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration