This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Problem with linking to shared native library
- From: Andrew Haley <aph at redhat dot com>
- To: Andreas Bürgel <Andreas dot Buergel at web dot de>
- Cc: java at gcc dot gnu dot org
- Date: Sat, 24 Mar 2007 17:14:06 +0000
- Subject: Re: Problem with linking to shared native library
- References: <45EC82D5.70606@web.de> <46043154.9020209@web.de>
Andreas Bürgel writes:
> Andreas Bürgel schrieb:
> > I've got a linking problem. Referencing a native C++ method in an shared library
> > causes this error:
> >
> > gcj -O0 -g --main=de.dbt.simplelibclient.SimpleCPPLib
> > de/dbt/simplelibclient/SimpleCPPLib.o -oDebug/SimpleLibClient -LDebug
> > -L/home/andreas/develop/projects/SimpleCPPLib/Debug -L../SimpleCPPLib/Debug
> > -lSimpleCPPLib -lgcj
> > de/dbt/simplelibclient/SimpleCPPLib.o:(.data+0xc): undefined reference to
> > `hidden alias for de::dbt::simplelibclient::SimpleCPPLib::square(int)'
> > de/dbt/simplelibclient/SimpleCPPLib.o:(.data+0x68): undefined reference to
> > `hidden alias for de::dbt::simplelibclient::SimpleCPPLib::square(int)'
> > collect2: ld returned 1 exit status
>
> In the meantime I tested with a gcc 4.0.4 built from the release
> sources. With this gcc version the executable builds fine without
> errors and runs as expected. The other parts of my environment
> didn't change, so this looks like a problem of gcc version > 4.0.4
> I attached my current example also containing the output of failure
> build with "gcc/gcj -v" (4.1.2) and "nm -C" of the shared lib.
This doesn't make any sense. You're trying to define a native method
SimpleCPPLib.square() in a shared library and define the rest of the
SimpleCPPLib class in the executable. Either the whole class, native
and Java methods, gets defined in the executable or it dets defined in
the shared library.
You can't split a single class across libraries. C++ and Java parts
have to be in the same loadable object.
Andrew.