Problem with linking to shared native library

Andrew Haley aph@redhat.com
Tue Mar 6 11:25:00 GMT 2007


Andreas Bürgel writes:
 > Sorry for the inconvenience, new installed mailer ...
 > 
 > 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
 > 
 > I've attached the example C++ lib and the Java class using the lib. Just unpack
 > the archive simplecpplib_sample.tar.bz2 in an empty dir and run "build.sh".
 > 
 > My platform:
 > - gcj version: 4.1.2 20061115
 > - binutils version: 2.17.50.0.5 20060927
 > - OS: openSUSE 10.2, Linux kernel 2.6.18.2-34-default
 > - glibc version: 2.5 (20061011)
First thing:
gcj -shared -o"libSimpleCPPLib.so" ./SimpleCPPLib.o 
/usr/bin/ld: ./SimpleCPPLib.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
./SimpleCPPLib.o: could not read symbols: Bad value
So I recompiled PIC, then:
zebedee:/tmp/foo $ ./build.sh 
Building file: ../SimpleCPPLib.cc
Invoking: GCC C++ Compiler
g++ -fPIC -O0 -g3 -Wall -c -MMD -MP -MF"SimpleCPPLib.d" -MT"SimpleCPPLib.d" -o"SimpleCPPLib.o" "../SimpleCPPLib.cc"
Finished building: ../SimpleCPPLib.cc
 
Building target: libSimpleCPPLib.so
Invoking: GCC C++ Linker
gcj -fPIC -shared -o"libSimpleCPPLib.so" ./SimpleCPPLib.o 
Finished building target: libSimpleCPPLib.so
 
/tmp/foo
mkdir -p Debug/resource
gcj -O0 -g "--classpath=./:" -c de/dbt/simplelibclient/SimpleCPPLib.java -o de/dbt/simplelibclient/SimpleCPPLib.o
de/dbt/simplelibclient/SimpleCPPLib.java:3: warning: The import de.dbt.simplelibclient is never used
 import de.dbt.simplelibclient.*;
 ^^^^^^^^^^^^^^^^^^^^^^
1 problem (1 warning)
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 
/tmp/foo
So I tried it, with:
zebedee:/tmp/foo $ LD_LIBRARY_PATH=SimpleCPPLib/Debug ./SimpleLibClient/Debug/SimpleLibClient
Exception in thread "main" java.lang.UnsupportedOperationException: de::dbt::simplelibclient::SimpleCPPLib::square (jint) not implemented
 at de.dbt.simplelibclient.SimpleCPPLib.main(SimpleCPPLib.java:16)
which comes from:
jint
de::dbt::simplelibclient::SimpleCPPLib::square (jint)
{
 throw new ::java::lang::UnsupportedOperationException (JvNewStringLatin1 ("de::dbt::simplelibclient::SimpleCPPLib::square (jint) not implemented"));
}
Andrew.


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /