Problem with linking to shared native library
Andrew Haley
aph@redhat.com
Sat Mar 24 17:14:00 GMT 2007
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.
More information about the Java
mailing list