Inherited linking problem

Andrew Haley aph@redhat.com
Tue Feb 6 10:02:00 GMT 2007


Bu Bacoo writes:

 > Please, how do I link some 'inherited' objects? Explained: I want to
 > build simple test program, which uses log4j (building it with Sun's
 > JDK into .class bytecode and running inside their VM works ok)
 > 
 > gcj -o logTest --main=logTest --classpath=./log4j.jar logTest.java
 > 
 > I get:
 > /tmp/ccmlhniA.o: In function `logTest::__U3c_clinit__U3e_()':
 > logTest.java:(.text+0x16): undefined reference to
 > `org::apache::log4j::Category::getInstance(java::lang::String*)'
 > /tmp/ccmlhniA.o: In function `logTest::main(JArray<java::lang::String*>*)':
 > logTest.java:(.text+0x295): undefined reference to
 > `org::apache::log4j::Priority::class$'
 > logTest.java:(.text+0x2ad): undefined reference to
 > `org::apache::log4j::Priority::DEBUG'
 > /tmp/ccmlhniA.o:(.data+0x188): undefined reference to
 > `org::apache::log4j::Category::class$'
 > collect2: ld returned 1 exit status
 > 
 > libgcj.jar is linked by default, log4.jar was added by me. Is there
 > neccessity of some additional libraries, which are not included in
 > log4j but maybe I can get them from some jvm's libs?
 > 
 > Any idea please?

I'm pretty sure that this is not so much a bug as a misunderstanding.
Generally speaking, when you precompile code with gcj you must include
all the objects that it depends on.  The easiest thing to do is to
compile things separately and link them together at the end.

In your case it's probably as simple as:

gcj -c -o log4j.o log4j.jar
gcj -c -o logTest.o --classpath=./log4j.jar logTest.java
gcj -o logTest --main=logTest log4j.o logTest.o

Thre are many other ways of doing things with gcj that may turn out to
be more suitable for your purposes, such as creating shared libraries
from .jar files, but this is the simplest.

Andrew.



More information about the Java mailing list