Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-29-2013, 04:09 AM   #1
LQ Newbie
Registered: Mar 2013
Posts: 1

Rep: Reputation: Disabled
compilation error for c++ code

I am getting the below error, when i am trying to compile code below.

Error: main.cpp: In function ‚int main()‚:
main.cpp:6: error: ‚display‚ was not declared in this scope

class Test
friend int display();


int display()
cout<<"Hello:In"<< endl;
return 0;


int main()
return 0;

Strange thing is I am able to compile in unix successfully , but in linux OS getting this error.
I am using gcc and g++ compiler
Old 03-29-2013, 04:28 AM   #2
LQ Guru
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,658

Rep: Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852Reputation: 2852
please use [code]your code[/code] to keep formatting.
class Test is not in use at all.
I would like to see how can you compile it successfully and how it went wrong. (what was the OS, the command and the result)
Old 03-29-2013, 05:20 PM   #3
Registered: Feb 2013
Location: Berlin
Distribution: Gentoo, Debian
Posts: 172

Rep: Reputation: 25
The class refers to a function named "display" which is not defined at that point. Also, class "Test" is not created or used anywhere in the code, so why not delete the entire "class Test" thing?
Old 03-29-2013, 11:54 PM   #4
John VV
LQ Muse
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,181

Rep: Reputation: 2505Reputation: 2505Reputation: 2505Reputation: 2505Reputation: 2505Reputation: 2505Reputation: 2505Reputation: 2505Reputation: 2505Reputation: 2505Reputation: 2505
from that you copied "test1.h" into /usr/include
the < > tell it to look there
and NOT in the build folder

if test1.h is in the same folder as main.cpp use
#include "test1.h"


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
Compilation of C++ code with Purify henrysimon Solaris / OpenSolaris 6 06-28-2012 12:39 AM
Switches controlling the code compilation -- How to kk2202 Programming 1 08-28-2009 10:18 AM
D-ITG compilation error - me or the code? baldy3105 Linux - Software 2 12-08-2006 04:47 AM
Compilation error while mixing C & C++ code. mghiya Programming 3 04-11-2006 09:45 AM
compilation error - code 2 jhon Programming 2 08-31-2004 01:54 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:38 PM.

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