Calling Java class from C++ Build Errors

D

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\Makefile.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.
 
V

Victor Bazarov

Dan said:
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\Makefile.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

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
 
R

Rolf Magnus

Victor said:
C++ calling Java is undefined by C++ language, you know. You're in
the are that is not really topical in comp.lang.c++...


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.
 
V

Victor Bazarov

Rolf said:
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
 
D

Dan

Thought I'd got the wrong group. Thanks for the replies though; its
given me some more avenues to try.

Cheers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top