473,799 Members | 3,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

compilation problems!!

I have problem compiling this program using GCC(g++)

//bye.h --header file
#ifndef BYE_H
#define BYE_H
void display();
#endif

//bye.C -------- Source
#include "bye.h"
#include <iostream.h>

void display()
{
cout <<"Display the stuff ";

}

//main.cpp -----source
#include <iostream.h>
#include <string.h>
#include "bye.h"

class myclass
{
//mystruct x;
friend void display();
public:
myclass(){
display();
}
};

int main()
{
myclass me;

}

If I compile using g++ main.cpp I get the following error,

/tmp/ccG3OvUb.o: In function `myclass::mycla ss[in-charge]()':
/tmp/ccG3OvUb.o(.gnu .linkonce.t._ZN 7myclassC1Ev+0x 7): undefined
reference to `display()'
collect2: ld returned 1 exit status

Can some body explain how to do it
thanks in advance,
Seema Rao

Jul 18 '06 #1
7 1479

"seema" <se********@yah oo.co.inwrote in message
news:11******** **************@ 35g2000cwc.goog legroups.com...
>I have problem compiling this program using GCC(g++)
//bye.C -------- Source
The .C is probably triggering g++ to compile this as a C module.
#include "bye.h"
#include <iostream.h>
An unrelated issue; you should switch to <include>.
void display()
{
cout <<"Display the stuff ";
I suspect g++ can then compile C++ things in a C module. But that is
platform-specific, so you should ask a g++ forum.
class myclass
{
//mystruct x;
friend void display();
public:
myclass(){
display();
}
};
Can you also just call display() directly from main(), without the friend?
/tmp/ccG3OvUb.o: In function `myclass::mycla ss[in-charge]()':
/tmp/ccG3OvUb.o(.gnu .linkonce.t._ZN 7myclassC1Ev+0x 7): undefined
reference to `display()'
Google for "name mangling". I suspect the .C extension has mangled the name
display() for C, not C++. Linkers generally only link mangled names that
match.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Jul 18 '06 #2
seema wrote:
[..]
If I compile using g++ main.cpp I get the following error,

/tmp/ccG3OvUb.o: In function `myclass::mycla ss[in-charge]()':
/tmp/ccG3OvUb.o(.gnu .linkonce.t._ZN 7myclassC1Ev+0x 7): undefined
reference to `display()'
collect2: ld returned 1 exit status

Can some body explain how to do it
Somebody in 'gnu.g++.help' should be able to. You must be compiling
those translation units separately. You need to "link" them together
during linking. How to do that is compiler-specific and off-topic.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 18 '06 #3
seema wrote:
I have problem compiling this program using GCC(g++)

//bye.h --header file
#ifndef BYE_H
#define BYE_H
void display();
#endif

//bye.C -------- Source
change the name of the file to bye.cpp - it will make your life much
easier if you are consistent.
#include "bye.h"
#include <iostream.h>
Change the above line to:
#include <iostream>
void display()
{
add the following line here:
using namespace std;
cout <<"Display the stuff ";

}

//main.cpp -----source
#include <iostream.h>
Change the above line to:
#include <iostream>
#include <string.h>
Delete the above line - you don't need that header in this program.
#include "bye.h"

class myclass
{
//mystruct x;
friend void display();
Delete the above line - you don't need it in this program.
public:
myclass(){
display();
}
};

int main()
{
myclass me;

}

If I compile using g++ main.cpp I get the following error,

/tmp/ccG3OvUb.o: In function `myclass::mycla ss[in-charge]()':
/tmp/ccG3OvUb.o(.gnu .linkonce.t._ZN 7myclassC1Ev+0x 7): undefined
reference to `display()'
collect2: ld returned 1 exit status

Can some body explain how to do it
<implementati on specific/>

If you are on Linux, compile it as follows:

g++ -Wall -Wextra -pedantic main.cpp bye.cpp -o seema

and execute it by typing:

seema

If you are on Windows, compile it as follows:

g++ -Wall -Wextra -pedantic main.cpp bye.cpp -o seema.exe

and execute it by typing:

seema

</implementation specific>

Hope that helps.

Best regards,

Tom

Jul 18 '06 #4

"Phlip" <ph******@yahoo .comwrote in message
news:iG******** ***********@new ssvr12.news.pro digy.com...
>
"seema" <se********@yah oo.co.inwrote in message
news:11******** **************@ 35g2000cwc.goog legroups.com...
>>I have problem compiling this program using GCC(g++)
>//bye.C -------- Source

The .C is probably triggering g++ to compile this as a C module.
>#include "bye.h"
#include <iostream.h>

An unrelated issue; you should switch to <include>.
huh?
Jul 18 '06 #5
Howard wrote:
"Phlip" <ph******@yahoo .comwrote in message
news:iG******** ***********@new ssvr12.news.pro digy.com...
>>
"seema" <se********@yah oo.co.inwrote in message
news:11******* *************** @35g2000cwc.goo glegroups.com.. .
>>I have problem compiling this program using GCC(g++)
>>//bye.C -------- Source

The .C is probably triggering g++ to compile this as a C module.
>>#include "bye.h"
#include <iostream.h>

An unrelated issue; you should switch to <include>.

huh?
I think "Phlip" meant <iostream>

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 18 '06 #6
Thomas Tutone wrote:
If you are on Linux, compile it as follows:

g++ -Wall -Wextra -pedantic main.cpp bye.cpp -o seema
-Wextra is only available on quite recent versions. Older ones want -W
instead. I would also add -ansi.
and execute it by typing:

seema
On a sane installation, this won't work. Better try:

./seema

Jul 18 '06 #7

Rolf Magnus wrote:
Thomas Tutone wrote:
If you are on Linux, compile it as follows:

g++ -Wall -Wextra -pedantic main.cpp bye.cpp -o seema

-Wextra is only available on quite recent versions. Older ones want -W
instead. I would also add -ansi.
and execute it by typing:

seema

On a sane installation, this won't work. Better try:

./seema
Quite right. Thanks for the correction.

Best regards,

Tom

Jul 18 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1465
by: Craig Reynolds | last post by:
Hi, I'm having problems compiling php 4.3.4 on HPUX 11.0 After configure completes successfully, I type make and the following happens: $ make gcc -Iext/ctype/ -I/staff/cyp/creyn003/src/WWW/php-4.3.4/ext/ctype/ -DPHP_ATOM_INC
2
2058
by: Olaf Meyer | last post by:
I'm having some problems compiling Python 2.3.3 on HP-UX (B.11.00). I've tried sevral different options for the configure script (e.g. enabling/disabling gcc, aCC) but I always get the same problem during the final linking stage. Several PyThread_* symbols are undefined (for details see the output below). In order to get DCOracle2 support working I've also set the LDFLAGS environment variable to "-lpthread -lcl" (as mentioned in the...
1
1402
by: wallygato11 | last post by:
Sigh, I'm stumped so if anyone could help me it would be much appreciated. Ok I'll describe the problem as best I can. I am trying to use an application called ACCPM to solve optimization problems but the program needs to be compiled before I can use it. If you want to try it for yourself you can download all the necessary files at
1
1861
by: awaegel | last post by:
Hello, I've been running php/apache/etc locally on my powerbook for a long time, but am having problems activating freetype with a new version of php. I'm using: php 4.4.0 freetype 2.1.10 (compiled from source) gd 2.0.28 (came with php)
3
2242
by: Krivenok Dmitry | last post by:
I writing simple class CmdLine: ..... ..... class CmdLine { ..... ..... public: /// Constructor CmdLine(int argc, char** argv);
6
9804
by: alban | last post by:
Hello I have got some problems of compilation on a AIX IBM, I use the XLC compilator (And I can't install another one). I try to compile code Pro*c ".pc" (oracle), I need do a pre-compilation after the pre-compilation with the my makefile I get the files ".c" After this a get also the objects files ".o", but no linkage ! and I can't have the exec file ! I have got some errors how I dont understand really :
1
1164
by: Mark Olbert | last post by:
I don't know if these two problems are related or if they're independent. In moving my site to a production server I discovered that I had enabled T-SQL debugging and forgotten to turn it off (I'm deploying the debug version on the production server to continue doing some "real world" testing). Because my hosting company doesn't grant debugging permissions on their instance of SqlServer this prevented connections from being created. No...
1
1224
by: vasant63 | last post by:
Hi, This is the compilation errors which I am getting when I compiling the code with VC++ 6.0. The same code is getting compiled in Linux OS. I would like to know how this compiler error can be eliminated? d:\vasant\mysys\encoder\events.cpp(40) : error C2511: 'Register' : overloaded member function 'void (enum EventType,void (__cdecl *)(enum EventType,void *,void *),void *)' not found in 'EventManager'...
4
3695
by: Chuck Chopp | last post by:
I have an application that I originally built using Visual Studio .NET 2003 as native C++ . This application includes a template class that was derived from the string class that's part of the C++ STL. Specifically, it extends the class with some additional methods to support changes in encoding as well as sprintf-style in-place formatting. Now, I've been asked to provide a version of the application running on Linux. I'm using GCC as...
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.