473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

trouble with linking of c wrapper around c++ class (gcc)

Hi,

I am trying to make a wrapper in c so i can compile a program using
c++ code in gcc.

The next setup actually works, but when i try to use it with c++
classes i get "undefined reference to `__gxx_personality_v0' collect2:
ld returned 1 exit status"

WORKING SETUP:

test1a.cpp:

extern "C" int tomroot(int x)
{
int y = x * x;
return y;
}
_____________________________

test1b.c:

#include "stdio.h"

int tomroot(int);

int main() {
int x = 6;
printf("%d\n",tomroot(x));
}

_____________________________

commandline: g++ -c test1a.cpp; gcc -c test1b.c; gcc test1a.o test1b.o
-o test1

FAILING SETUP:

mcc.h:

#ifndef MCC_H
#define MCC_H

class mcc {

public:
int tomroot( int x );

};

#endif
_____________________________

mcc.cpp:

#include "mcc.h"

int mcc::tomroot( int x )
{
int y = x * x;
return y;
};
_____________________________

mccintermediate.cpp:

#include "mcc.h"

extern "C" int intermediatetomroot( int x )
{
mcc temp;
return temp.tomroot( x );
}
_____________________________

mccintermediatetestc.c:

#include "stdio.h"

int intermediatetomroot( int x );

int main()
{
printf("%d\n", intermediatetomroot( 5 ));
}
_____________________________

commandline: g++ -c mcc.cpp mccintermediate.cpp; gcc -c
mccintermediatetestc.c; gcc mcc.o mccintermediate.o
mccintermediatetestc.o -o mccintermediatetestc

which outputs, as mentioned above:
mccintermediate.o(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status

Anybody has a clue ? Suggesting using g++ to compile the c code won't
do me no good, i need a c compiler ( eg gcc ) doing this job.

Thanks in advance, Tom.
Jul 22 '05 #1
2 1614
se******@hotmail.com wrote:
[...]
commandline: g++ -c mcc.cpp mccintermediate.cpp; gcc -c
mccintermediatetestc.c; gcc mcc.o mccintermediate.o
mccintermediatetestc.o -o mccintermediatetestc
Although it is off-topic here and next time you should ask in a G++
newsgroup, here is a possible solution: use 'g++' to link instead of
'gcc'.

which outputs, as mentioned above:
mccintermediate.o(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status

Anybody has a clue ? Suggesting using g++ to compile the c code won't
do me no good, i need a c compiler ( eg gcc ) doing this job.


Whatever.

V
Jul 22 '05 #2
se******@hotmail.com wrote:
commandline: g++ -c mcc.cpp mccintermediate.cpp; gcc -c
mccintermediatetestc.c; gcc mcc.o mccintermediate.o
mccintermediatetestc.o -o mccintermediatetestc

which outputs, as mentioned above:
mccintermediate.o(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status

Anybody has a clue ? Suggesting using g++ to compile the c code won't
do me no good, i need a c compiler ( eg gcc ) doing this job.


First, your example works with GCC 3.3.3 for Cygwin. However, in a
mixed C/C++ application it is sometimes required that main() be com-
piled as C++. You might have to compile main() with g++, though it
can delegate to a C main if you wish:

// main.cpp:
extern "C" int C_main(int, char**);
int main(int argc, char** argv) {
return C_main(argc, argv);
}
Jul 22 '05 #3

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

Similar topics

0
by: Wolfgang | last post by:
I have a problem with linking my CPP Code under a irix6 machine (sgi, UNIX). In my CPP code I use some Functions which are written in Python. So its a kind of CPP wrapper for my Python functions In...
3
by: Thomas Ruschival | last post by:
Hi, as far as I know I can link all C libraries in C++ as well. but I can't get it done with pslib. pslib is a library to create Postscript documents. The exactly same code compiles and links...
0
by: DotNetJunkies User | last post by:
Background: I am creating a VC++ .NET wrapper for a C++ DLL; the aim is to use this wrapper in C# as shown below: Range r = new Range( 2, 2 ); r = new Cell( “Hello Mum” ); Range is a...
1
by: Christoph Wienands | last post by:
Hello everybody, I'm a C# programmer that recently was forced to look into Managed C++. Please forgive me if I might be asking stupid questions ;-) I currently have to write a wrapper class...
16
by: utab | last post by:
Dear all, In programming terminology, what is a wrapper and where is it used? Regards
8
by: Jim Anderson | last post by:
It's been a few years since I have programmed in C++. I'm starting to develop some programs in C++ and I can't get "Hello, World" working yet. It looks to me like 'cout' in the std library is not...
2
by: pssraju | last post by:
Hi, At present application was built on solaris 9 using sun studio 9 (Sun C++ 5.6) & rouguewave sorce pro 5. We are planning to port the same application onto SuSE Linux 9.5.0 using GCC 3.3.3 & RW...
6
by: Joe.pHsiao | last post by:
Hi, I tried to link a C program to a library which is written by me in C+ +. I read some posts about linking a C program to C++ libraries. It seems doable by adding extern "C" to the C++ head...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.