473,406 Members | 2,707 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,406 software developers and data experts.

Calling Java class from C++ Build Errors

Dan
Hi All,

I've got a problem with my C++ application that calls a Java class
that I've built with GCJ, I can't run it because I get errors:

multiple definition of `atexit'
first defined here
multiple definition of `_onexit'
first defined here
multiple definition of `__do_sjlj_init'
first defined here
BFD 2.15.91 20040904 assertion fail ../../src/bfd/cofflink.c:2269
illegal symbol index 1091667985 in relocs
ld returned 1 exit status
D:\Dev\Interceptor\Prototypes\CPP\JavaExperiment\M akefile.win [Build
Error] [JavaExperiment.exe] Error 1

Some background information:

I've written a very simple class in Java with a single method call in
it, I complied this to an object file (.o) using GCJ and then
generated a C++ header file using GCJH.

gcj -shared -o NewClass.o NewClass.java
gcjh NewClass

I'm developing the C++ component in Dev C++ so I've added the .o file
as a reference and included the .h file.

The C++ file is really simple:

#include <cstdlib>
#include <iostream>
#include <gcj/cni.h>
#include "NewClass.h"

using namespace std;

int main(int argc, char *argv[])
{
system("PAUSE");
return EXIT_SUCCESS;
}

Is there some option I am missing in perhaps GCJ to stop it from
creating the atexit function? It all builds fine when I remove the
reference to my .o file.

Any help would be greatly appreciated...
Cheers,
Dan Alexander.
Dec 20 '07 #1
4 2769
Dan wrote:
I've got a problem with my C++ application that calls a Java class
C++ calling Java is undefined by C++ language, you know. You're in
the are that is not really topical in comp.lang.c++...
that I've built with GCJ,
We here have really no idea what 'GCJ' is, unless you tell us.
I can't run it because I get errors:

multiple definition of `atexit'
first defined here
multiple definition of `_onexit'
first defined here
multiple definition of `__do_sjlj_init'
first defined here
BFD 2.15.91 20040904 assertion fail ../../src/bfd/cofflink.c:2269
illegal symbol index 1091667985 in relocs
ld returned 1 exit status
Multiple definition is usually due to [mis]use of standard libraries,
for example, you link with two of them from different compilers.
D:\Dev\Interceptor\Prototypes\CPP\JavaExperiment\M akefile.win [Build
Error] [JavaExperiment.exe] Error 1

Some background information:

I've written a very simple class in Java with a single method call in
it, I complied this to an object file (.o) using GCJ and then
generated a C++ header file using GCJH.
All that is specific to Java, not to C++.
>
gcj -shared -o NewClass.o NewClass.java
gcjh NewClass
<shrugOK
>
I'm developing the C++ component in Dev C++ so I've added the .o file
as a reference and included the .h file.
Dev C++ is not really topical either. This is a _language_ newsgroup,
sorry.
>
The C++ file is really simple:

#include <cstdlib>
#include <iostream>
I don't believe you're using any part of it.
#include <gcj/cni.h>
That is a non-standard header. Whatever errors come out from using
it cannot be rectified through standard C++ means. You probably need
to contact those from whom you got the header.
#include "NewClass.h"
Whatever that is. The contents of it are unknown, so nothing can be
said about the possibility of errors arising from using it. But you
said it was your own header. Make sure there are no "atexit" defined
in it.
>
using namespace std;

int main(int argc, char *argv[])
If you don't use 'argc', 'argv', there is no need to declare them.
{
system("PAUSE");
return EXIT_SUCCESS;
}

Is there some option I am missing in perhaps GCJ to stop it from
creating the atexit function? It all builds fine when I remove the
reference to my .o file.

Any help would be greatly appreciated...
Not sure what you expect, Dan. The best thing would probably be to
post your Java-specific question in a Java newsgroup. They (Java)
tend to define a lot more (as part of their specification) than C++
does, interaction with C++ is one of those well-defined elements,
IIRC. All I can recommend is to examine what libraries you give to
your linker to see which ones have definitions of 'atexit' (and
the other functions), and then [try to] remove one of them from the
linker command line.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 20 '07 #2
Victor Bazarov wrote:
Dan wrote:
>I've got a problem with my C++ application that calls a Java class

C++ calling Java is undefined by C++ language, you know. You're in
the are that is not really topical in comp.lang.c++...
>that I've built with GCJ,

We here have really no idea what 'GCJ' is, unless you tell us.
I could tell you. It's the Java part of the Gnu Compiler Collection. AFAIK,
it produces native code, so it's not a typical java compiler. I'd say a
good newsgroup to ask would be gnu.gcc.help or gnu.g++.help.

Dec 20 '07 #3
Rolf Magnus wrote:
Victor Bazarov wrote:
>Dan wrote:
>>I've got a problem with my C++ application that calls a Java class

C++ calling Java is undefined by C++ language, you know. You're in
the are that is not really topical in comp.lang.c++...
>>that I've built with GCJ,

We here have really no idea what 'GCJ' is, unless you tell us.

I could tell you. It's the Java part of the Gnu Compiler Collection.
AFAIK, it produces native code, so it's not a typical java compiler.
I'd say a good newsgroup to ask would be gnu.gcc.help or gnu.g++.help.
And Dan's problems are likely because 'GCJ' provides its own 'atexit'
in its own perverted way, so a C++ object module needs to use a lot
of caution if it tries to link with a GCJ object module to form
a functional bond (executable module). Happens all the time when
two languages collide in a way they weren't designed to.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 20 '07 #4
Dan
Thought I'd got the wrong group. Thanks for the replies though; its
given me some more avenues to try.

Cheers.
Jan 14 '08 #5

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

Similar topics

9
by: FISH | last post by:
Ever have one of those days when you're not sure if it's you who's gone mad, or the rest of the world? I have an Open Source project on SourceForge for communication with YSMG - Yahoo's IM...
55
by: Elijah | last post by:
I have read many of the topics on learning C++ or Java first. It seems like everyone says something different. I would like to know if I should learn C++ or Java. First a little about myself. I...
12
by: johny smith | last post by:
I am trying to figure out a way to print the address of what called a certain function once inside the function. I am assuming that this information is on the stack somewhere. But can someone...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
2
by: ramasubramanian.rahul | last post by:
hi i am trying to call some java APIs from c . i use the standatd JNI calls to load the JVM from a c program and call all java functions by using a pointer to the jvm which was returned by the JNI...
35
by: mwelsh1118 | last post by:
Why doesn't C# allow incremental compilation like Java? Specifically, in Java I can compile single .java files in isolation. The resulting individual .class files can be grouped into .jar files....
5
by: PeaceLovinHippy | last post by:
Hello im new to java & im working on some mods for a game - below is a small part which im working on . however im getting errors due to something wrong in the code - can anyone please help me...
5
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is...
7
by: jomcfall97 | last post by:
hey wondering if anyone can help me with some work im doing im trying to remove a record from a queue by using a method from a class. class QueueNode { private String document ; private String...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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...
0
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...
0
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...

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.